2014-06-22 80 views
1

我正在使用mysql。在我的本地机器上,我有3次迁移,在服务器上我有将近9次。我将我的代码+迁移到github。在服务器上拉它。在South迁移时遇到问题

使用./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'") 

回答

2

为什么没有你的服务器上运行的原因是,可能是你的本地计算机上,你有不同的数据库......

我建议要检查什么是什么是在你的服务器和数据库models.py。当models.py中的代码将等于您的数据库时,您可以从服务器中删除所有迁移。比再简单地使用南方。

python manage.py schemamigration app --initial python manage.py migrate app

+0

你有什么不同的数据库呢? models.py有一个额外的列,我想添加。我在本地机器上迁移了数据库。在服务器上迁移。但由于此问题,更改不会反映在服务器上的数据库中。 – Naman

+1

问题是,你的服务器上的数据库不同于服务器上的迁移...就像我建议评论所有新的“额外的列”,然后删除迁移和使用 - 初始 – Silwest

+0

你的意思是来自models.py的额外列? – Naman