我最近签出了一个项目的主分支,有一些模型更改尚未反映在迁移中:
(venv) Kurts-MacBook-Pro-2:lucy-web kurtpeek$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auditlog, auth, contenttypes, lucy_web, oauth2_provider, otp_static, otp_totp, sessions, two_factor
Running migrations:
No migrations to apply.
Your models have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
按照说明,我运行makemigrations
来创建它们:
有趣的是,0009_auto_20180425_1129.py
迁移是在包含Django的源代码(版本1.11.9)的venv
中创建的,我不认为我们团队中的任何人都改变了这一点。以下是迁移:
# -*- coding: utf-8 -*-
# Generated by Django 1.11.9 on 2018-04-25 18:29
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auth', '0008_alter_user_username_max_length'),
]
operations = [
migrations.AlterField(
model_name='user',
name='email',
field=models.EmailField(blank=True, max_length=254, unique=True, verbose_name='email address'),
),
]
它看起来“足够无辜”,但当我尝试迁移时,我得到了以下结果ProgrammingError
:
(venv) Kurts-MacBook-Pro-2:lucy-web kurtpeek$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auditlog, auth, contenttypes, lucy_web, oauth2_provider, otp_static, otp_totp, sessions, two_factor
Running migrations:
Applying auth.0009_auto_20180425_1129...Traceback (most recent call last):
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "auth_user_email_1c89df09_uniq" already exists
在django.db.utils.ProgrammingError: relation already exists处的一些答案似乎相当激烈,例如删除所有迁移或使用命令选项^{
你知道怎么解决这个错误吗?在
事实证明,
auth_user_email_1c89df09_uniq
关系实际上是一个约束(所以不是数据)。我通过简单地删除/删除pgAdmin中的这个约束就成功地进行了迁移,并且对auth_user_email_1c89df09_like
索引(之后弹出了一个ProgrammingError
)进行了类似的迁移。在在这之后,我可以迁移:
约束和索引已放回
auth_user
表中:试试这个,这会有用的:
注意:此字段中的所有数据都将丢失
在运行了最后一次迁移之后,您就有了这个文件
0009_auto_20180425_1129.py
正在等待迁移。。。如果不再有此文件,请重新运行makemigrations
,让最后一个迁移文件等待migrate
。在在您的案例中,浏览该文件
0009_auto_20180425_1129.py
,然后进入其中operations
添加以下行:
相关问题 更多 >
编程相关推荐