本文介绍了重复列名称'model_id'django mysql错误迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的VPS上使用Django和MySQL。每当我运行 python manage.py migrate
我收到以下错误。但是在我的开发服务器上,我使用sqlite,并且迁移工作正常。 运行迁移:
呈现模型状态.. 。DONE
应用bloupergroups.0002_auto_20160826_1138 ...追溯(最近调用最后):
文件manage.py,第10行,< module>
execute_from_command_line(sys.argv)
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/core/management/__init__.py,第353行,在execute_from_command_line
utility.execute()
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/core/management/__init__.py中,行345,执行
self.fetch_command(子命令).run_from_argv(self.argv)
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django /core/management/base.py,第348行,在run_from_argv
self.execute(* args,** cmd_options)
文件/ home / ashish / Env / bloup / local / lib / python2 .7 / site-packages / django / core / management / base.py,第399行,执行
output = self.handle(* args,** options)
文件/ home / ashish /Env/bloup/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py,第200行,处理
executor.migrate(targets,plan,fake = fake ,fake_initial = fake_initial)
文件/ home / ashish / Env /bloup/local/lib/python2.7/site-packages/django/db/migrations/executor.py,第92行,迁移
self._migrate_all_forwards(plan,full_plan,fake = fake,fake_initial = fake_initial )
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/migrations/executor.py,第121行,_migrate_all_forwards
state = self.apply_migration(state,migration,fake = fake,fake_initial = fake_initial)
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/migrations/executor .py,第198行,apply_migration
state = migration.apply(state,schema_editor)
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/ django / db / migrations / migration.py,第123行,应用
operation.database_forwards(self.app_label,schema_editor,old_state,project_state)
文件/ home / ashish / Env / bloup / local /lib/python2.7/site-packages/django/db/migrations/operations/fields.py,第62行,在database_forwards
字段中,
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/mysql/schema.py,第50行,add_field
super(DatabaseSchemaEditor,self) .add_field(model,field)
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/base/schema.py,第396行,在add_field
self.execute(sql,params)
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/base/schema .py,行110,执行
cursor.execute(sql,params)
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/ db / backends / utils.py,行79,执行
return super(CursorDebugWrapper,self).execute(sql,params)
文件/ home / ashish / Env / bloup / local / lib /python2.7/site-packages/django/db/backends/utils.py,第64行,执行
return self.cursor.execute(sql,params)
文件/ home / ashish /Env/bloup/local/lib/python2.7/site-packages/django/db/utils.py,第95行,__exit__
six.rera ise(dj_exc_type,dj_exc_value,traceback)
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/utils.py,第64行,执行
return self.cursor.execute(sql,params)
文件/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/mysql /base.py,第112行,执行
return self.cursor.execute(query,args)
文件/home/ashish/Env/bloup/local/lib/python2.7/site $ pack $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / 7 / site-packages / MySQLdb / connections.py,第36行,defaulterrorhandler
raise errorvalue
django.db.utils.OperationalError:(1060,重复列名称blouper_id)
我不明白这里有什么问题。
解决方案
Django可能会尝试应用已应用的迁移。
尝试运行 python manage.py migrate --fake-initial
从文档:
I am using Django and MySQL on my VPS. Whenever I run python manage.py migrate
I get the following error. But on my development server I use sqlite, and migrate works fine.
Running migrations:
Rendering model states... DONE
Applying bloupergroups.0002_auto_20160826_1138...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/ashish/Env/bloup/local/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 "/home/ashish/Env/bloup/local/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 "/home/ashish/Env/bloup/local/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 "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/ashish/Env/bloup/local/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 "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 62, in database_forwards
field,
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/mysql/schema.py", line 50, in add_field
super(DatabaseSchemaEditor, self).add_field(model, field)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 396, in add_field
self.execute(sql, params)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 110, in execute
cursor.execute(sql, params)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 112, in execute
return self.cursor.execute(query, args)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 226, in execute
self.errorhandler(self, exc, value)
File "/home/ashish/Env/bloup/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorvalue
django.db.utils.OperationalError: (1060, "Duplicate column name 'blouper_id'")
I do not understand what the problem is here.
解决方案
Django is probably trying to apply migrations that have already been applied.
Try running python manage.py migrate --fake-initial
From the docs:
这篇关于重复列名称'model_id'django mysql错误迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!