【问题标题】:Having problems migrating in South在南方移民有问题
【发布时间】:2014-08-12 14:01:20
【问题描述】:

我正在使用 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'")

【问题讨论】:

    标签: mysql django django-south


    【解决方案1】:

    它在您的服务器上不起作用的原因可能是在您的本地计算机上您有不同的数据库......

    我建议检查您的服务器数据库中的内容以及models.py 中的内容。当models.py 中的代码等于您的数据库时,您可以从服务器中删除所有迁移。而不是简单地再次使用 South。

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

    【讨论】:

    • 不同的数据库是什么意思? models.py 有一个我想添加的额外列。我在本地机器上迁移了数据库。迁移到服务器上。但由于此问题,更改未反映在服务器上的数据库中。
    • 问题是服务器上的数据库与服务器上的迁移不同......就像我建议评论所有新的“额外列”然后删除迁移并使用 --initial
    • 你的意思是models.py的额外列?
    • 从迁移目录中删除所有内容。创建了一个 --initial 迁移。我从models.py 中注释掉了xx 字段。 (xx 是我要添加到数据库的字段。)。添加了另一个 --auto 迁移,上面写着 0002_auto__del_field_xx。迁移了应用程序。给出错误 FATAL ERROR - 以下 SQL 查询失败:ALTER TABLE app_student DROP COLUMN xx CASCADE;错误是:(1091,“Can't DROP 'xx'; 检查列/键是否存在”)!在实际运行迁移过程中发现错误!中止。 !您可能可以通过以下方式恢复:=ALTER TABLEapp_studentADD COLUMNxxvarchar(3)NOTNULL DEFAULT '0';[]
    • 伴侣这不是一件很难的事情......我做了几次同样的事情......你的服务器数据库中有很多数据吗?也许更好的选择是创建一个新的数据库
    猜你喜欢
    • 2014-01-30
    • 2013-04-15
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 2014-09-17
    • 2023-04-05
    • 2017-06-08
    相关资源
    最近更新 更多