Python Django迁移没有从makemigrations中获取更改
我向Python Django迁移没有从makemigrations中获取更改,python,django,Python,Django,我向models.py添加了一个新模型,对应于我需要创建的一个新SQL表。我包括了一个字段,Id,它显然不喜欢这个字段,因为python manage.py migrate说它是一个重复的字段(可能是一个Id字段也被自动添加了或是其他什么) 这很好,所以我从模型中删除了该字段,并重新运行了python manage.py makemigrations,它正确地报告了Id字段正在被删除。我认为重新运行了python manage.py migrate,但仍然会出现相同的错误,即存在重复的Id字段
models.py
添加了一个新模型,对应于我需要创建的一个新SQL表。我包括了一个字段,Id
,它显然不喜欢这个字段,因为python manage.py migrate
说它是一个重复的字段(可能是一个Id
字段也被自动添加了或是其他什么)
这很好,所以我从模型中删除了该字段,并重新运行了python manage.py makemigrations
,它正确地报告了Id
字段正在被删除。我认为重新运行了python manage.py migrate
,但仍然会出现相同的错误,即存在重复的Id
字段
从models.py
:
class TII(models.Model):
Person_bnr_id = models.CharField(max_length = 128, unique = True)
COURSE_IDENTIFICATION = models.CharField(max_length = 128, unique = True)
Course_start = models.CharField(max_length = 128, unique = True)
Course_end = models.CharField(max_length = 128, unique = True)
TurnItIn_W01 = models.CharField(max_length = 128, unique = True)
TurnItIn_W02 = models.CharField(max_length = 128, unique = True)
TurnItIn_W03 = models.CharField(max_length = 128, unique = True)
TurnItIn_W04 = models.CharField(max_length = 128, unique = True)
TurnItIn_W05 = models.CharField(max_length = 128, unique = True)
TurnItIn_W06 = models.CharField(max_length = 128, unique = True)
TurnItIn_W07 = models.CharField(max_length = 128, unique = True)
TurnItIn_W08 = models.CharField(max_length = 128, unique = True)
TurnItIn_W09 = models.CharField(max_length = 128, unique = True)
TurnItIn_W10 = models.CharField(max_length = 128, unique = True)
TurnItIn_W11 = models.CharField(max_length = 128, unique = True)
TurnItIn_W12 = models.CharField(max_length = 128, unique = True)
从python manage.py migrate
:
(P27_D19) [root@mdbiawebappdev1 loeuk]# python manage.py migrate
Operations to perform:
Apply all migrations: admin, contenttypes, studentprogress, auth, sessions
Running migrations:
Rendering model states... DONE
Applying studentprogress.0100_tii...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/srv/P27_D19/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/srv/P27_D19/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/srv/P27_D19/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/srv/P27_D19/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/srv/P27_D19/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/srv/P27_D19/lib/python2.7/site-packages/django/db/migrations/executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/srv/P27_D19/lib/python2.7/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/srv/P27_D19/lib/python2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "/srv/P27_D19/lib/python2.7/site-packages/django/db/migrations/migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/srv/P27_D19/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 59, in database_forwards
schema_editor.create_model(model)
File "/srv/P27_D19/lib/python2.7/site-packages/sql_server/pyodbc/schema.py", line 535, in create_model
self.execute(sql, params or None)
File "/srv/P27_D19/lib/python2.7/site-packages/sql_server/pyodbc/schema.py", line 584, in execute
cursor.execute(sql, params)
File "/srv/P27_D19/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/srv/P27_D19/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/srv/P27_D19/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/srv/P27_D19/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
File "/srv/P27_D19/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 537, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: ('42S21', "[42S21] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Column names in each table must be unique. Column name 'Id' in table 'studentprogress_tii' is specified more than once. (2705) (SQLExecDirectW)")
showmigrations
输出显示0100_tii
迁移尚未应用
[X] 0099_student_referrer_email
[ ] 0100_tii
[ ] 0101_remove_tii_id
因此,我将删除
0100_tii
和0101_remove_tii_id
文件。然后可以重新运行makemigrations
。如果0100\u tii
所做的只是添加id字段,那么在对模型进行进一步更改之前,您可能不需要运行makemigrations
。showmigrations
输出显示0100\u tii
迁移尚未应用
[X] 0099_student_referrer_email
[ ] 0100_tii
[ ] 0101_remove_tii_id
因此,我将删除
0100_tii
和0101_remove_tii_id
文件。然后可以重新运行makemigrations
。如果0100_tii
所做的只是添加id字段,那么在对模型进行进一步更改之前,您可能不需要运行makemigrations
。showmigrations的输出是什么?@RaphaëlGomè的伟大问题,我现在将添加该信息。您可以向我们展示0100_tii
文件吗?@RaphaëlGomè是的,当然可以。现在添加。在我看来,这不像是一个迁移文件。showmigrations
的输出是什么?@RaphaëlGomè的好问题,我现在就添加这些信息。你能给我们看看0100_tii
文件吗?@RaphaëlGomès是的,当然。现在添加。在我看来,这不像是迁移文件。太棒了。你能解释一下在哪里可以找到这些文件以便我删除它们吗?这是我第一次。谢谢这也是我的直觉,@Hack-R:请继续与我聊天(见评论)@RaphaëlGomès当然,我现在就加入聊天。我的老板问了我一些问题,抱歉耽搁了。应用程序是studentprogress
,因此迁移文件将位于studentprogress/migrations/
。太棒了。你能解释一下在哪里可以找到这些文件以便我删除它们吗?这是我第一次。谢谢这也是我的直觉,@Hack-R:请继续与我聊天(见评论)@RaphaëlGomès当然,我现在就加入聊天。我的老板问了我一些问题,很抱歉耽搁了。应用程序是studentprogress
,因此迁移文件将位于studentprogress/migrations/
。