我正在使用mysql。在我的本地机器上我有3次迁移,在服务器上我有近9次。我将我的代码+迁移推送到github。把它拉到服务器上。
使用./manage.py migrate appname
它不起作用。然后我尝试了--merge
旗帜。它也没用!我是dbms的新手。需要帮忙。此处00008_merge_models
是使用文档中提供的./manage.py schemamigration appname --empty merge_models
的空迁移。
- Soft matched migration 0008 to 0008_merge_models.
Running migrations for appname:
- Migrating forwards to 0008_merge_models.
> appname:0002_auto__add_field_student_cv__add_field_student_status__chg_field_studen
FATAL ERROR - The following SQL query failed: ALTER TABLE `appname_student` ADD COLUMN `cv` varchar(100) NOT NULL DEFAULT '';
The error was: (1060, "Duplicate column name 'cv'")
! Error found during real run of migration! Aborting.
! Since you have a database that does not support running
! schema-altering statements in transactions, we have had
! to leave it in an interim state between migrations.
! You *might* be able to recover with: - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
= ALTER TABLE `appname_student` DROP COLUMN `cv` CASCADE; []
- no dry run output for delete_foreign_key() due to dynamic DDL, sorry
= ALTER TABLE `appname_student` DROP COLUMN `status` CASCADE; []
= DROP TABLE `appname_student_companyapplications` CASCADE; []
= DROP TABLE `appname_student_placedat` CASCADE; []
- no dry run output for alter_column() due to dynamic DDL, sorry
- no dry run output for delete_foreign_key() due to dynamic DDL, sorry
= ALTER TABLE `appname_job` DROP COLUMN `createdon` CASCADE; []
- no dry run output for alter_column() due to dynamic DDL, sorry
- no dry run output for alter_column() due to dynamic DDL, sorry
- no dry run output for alter_column() due to dynamic DDL, sorry
! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS (one that supports DDL transactions)
! NOTE: The error which caused the migration to fail is further up.
Error in migration: appname:0002_auto__add_field_student_cv__add_field_student_status__chg_field_studen
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/south/management/commands/migrate.py", line 111, in handle
ignore_ghosts = ignore_ghosts,
File "/usr/local/lib/python2.7/dist-packages/south/migration/__init__.py", line 220, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/usr/local/lib/python2.7/dist-packages/south/migration/migrators.py", line 254, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/usr/local/lib/python2.7/dist-packages/south/migration/migrators.py", line 329, in migrate_many
result = self.migrate(migration, database)
File "/usr/local/lib/python2.7/dist-packages/south/migration/migrators.py", line 133, in migrate
result = self.run(migration, database)
File "/usr/local/lib/python2.7/dist-packages/south/migration/migrators.py", line 114, in run
return self.run_migration(migration, database)
File "/usr/local/lib/python2.7/dist-packages/south/migration/migrators.py", line 84, in run_migration
migration_function()
File "/usr/local/lib/python2.7/dist-packages/south/migration/migrators.py", line 60, in <lambda>
return (lambda: direction(orm))
File "/home/byld/placement/placement/appname/migrations/0002_auto__add_field_student_cv__add_field_student_status__chg_field_studen.py", line 14, in forwards
keep_default=False)
File "/usr/local/lib/python2.7/dist-packages/south/db/generic.py", line 47, in _cache_clear
return func(self, table, *args, **opts)
File "/usr/local/lib/python2.7/dist-packages/south/db/generic.py", line 418, in add_column
self.execute(sql)
File "/usr/local/lib/python2.7/dist-packages/south/db/generic.py", line 282, in execute
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 69, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.OperationalError: (1060, "Duplicate column name 'cv'")
答案 0 :(得分:2)
它在您的服务器上运行的原因是,您的本地计算机上可能有不同的数据库......
我建议检查您的服务器数据库中的内容以及models.py
中的内容。当models.py
中的代码与您的数据库相同时,您可以从服务器中删除所有迁移。而不仅仅是再次使用南方。
python manage.py schemamigration app --initial
python manage.py migrate app