Naman
Naman

Reputation: 183

Having problems migrating in South

I am using mysql. On my local machine I have 3 migrations and on the server I have nearly 9. I pushed my code + migrations to github. Pulled it on the server.

used ./manage.py migrate appname

It didn't work. Then I tried with a --merge Flag. It also didn't work! I am really new to dbms. Need help. Here 00008_merge_models is an empty migration using ./manage.py schemamigration appname --empty merge_models as given in the docs.

- 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'")

Upvotes: 1

Views: 1273

Answers (1)

Silwest
Silwest

Reputation: 1620

The reason why it didn't work on your server is that probably on your local machine you had different database ...

I would suggest to check what is in your sever database and what's in the models.py. When code in models.py will be equal to your database you can remove all migrations from server. Than simply use South again.

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

Upvotes: 2

Related Questions