2014-06-22 82 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