Modify

Ticket #724 (assigned defect)

Opened 3 years ago

Last modified 2 years ago

South fails to migrate OneToOne to ForeginKey

Reported by: jbzdak@… Owned by: andrew
Priority: major Milestone: 1.0
Component: migrations Version: 0.7.3
Keywords: Cc:

Description

I'm using django 1.3 beta.

When trying to migrate from OneToOne? field to ForeginKey? field South fails with exception:

Running migrations for southbug:
 - Migrating forwards to 0002_auto__chg_field_testmodel2_fk__del_unique_testmodel2_fk.
 > southbug:0001_initial
 > southbug:0002_auto__chg_field_testmodel2_fk__del_unique_testmodel2_fk
 ! 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:   = ALTER TABLE `southbug_testmodel2` ADD CONSTRAINT `southbug_testmodel2_fk_id_uniq` UNIQUE (`fk_id`) []

 ! The South developers regret this has happened, and would
 ! like to gently persuade you to consider a slightly
 ! easier-to-deal-with DBMS.
 ! NOTE: The error which caused the migration to fail is further up.
Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_manager(settings)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/home/jb/programs/wnt/zlotKadryRejestracja/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/management/commands/migrate.py", line 105, in handle
    ignore_ghosts = ignore_ghosts,
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/__init__.py", line 191, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 221, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 292, in migrate_many
    result = self.migrate(migration, database)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 125, in migrate
    result = self.run(migration)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 99, in run
    return self.run_migration(migration)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 81, in run_migration
    migration_function()
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 57, in <lambda>
    return (lambda: direction(orm))
  File "/home/jb/programs/wnt/zlotKadryRejestracja/southbug/migrations/0002_auto__chg_field_testmodel2_fk__del_unique_testmodel2_fk.py", line 12, in forwards
    db.delete_unique('southbug_testmodel2', ['fk_id'])
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/db/generic.py", line 479, in delete_unique
    raise ValueError("Cannot find a UNIQUE constraint on table %s, columns %r" % (table_name, columns))
ValueError: Cannot find a UNIQUE constraint on table southbug_testmodel2, columns ['fk_id']

If you comment out appopriate db.delete_unique('rejestracja_validatorzajecialink', zajecia_id?) i get:

- Migrating forwards to 0003_auto__chg_field_validatorkurslink_validator__del_unique_validatorkursl.
 > rejestracja:0003_auto__chg_field_validatorkurslink_validator__del_unique_validatorkursl
 ! 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:   = ALTER TABLE `rejestracja_validatorkurslink` ADD CONSTRAINT `rejestracja_validatorkurslink_validator_id_uniq` UNIQUE (`validator_id`) []
   = ALTER TABLE `rejestracja_validatorkurslink` ADD CONSTRAINT `rejestracja_validatorkurslink_kurs_id_uniq` UNIQUE (`kurs_id`) []
   = ALTER TABLE `rejestracja_validatorzajecialink` ADD CONSTRAINT `rejestracja_validatorzajecialink_validator_id_uniq` UNIQUE (`validator_id`) []
   = ALTER TABLE `rejestracja_validatorzajecialink` ADD CONSTRAINT `rejestracja_validatorzajecialink_zajecia_id_uniq` UNIQUE (`zajecia_id`) []

 ! The South developers regret this has happened, and would
 ! like to gently persuade you to consider a slightly
 ! easier-to-deal-with DBMS.
 ! NOTE: The error which caused the migration to fail is further up.
Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_manager(settings)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/home/jb/programs/wnt/zlotKadryRejestracja/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/management/commands/migrate.py", line 105, in handle
    ignore_ghosts = ignore_ghosts,
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/__init__.py", line 191, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 221, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 292, in migrate_many
    result = self.migrate(migration, database)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 125, in migrate
    result = self.run(migration)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 99, in run
    return self.run_migration(migration)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 81, in run_migration
    migration_function()
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/migration/migrators.py", line 57, in <lambda>
    return (lambda: direction(orm))
  File "/home/jb/programs/wnt/zlotKadryRejestracja/rejestracja/migrations/0003_auto__chg_field_validatorkurslink_validator__del_unique_validatorkursl.py", line 24, in forwards
    db.alter_column('rejestracja_validatorkurslink', 'validator_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['rejestracja.Validator']))
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/db/generic.py", line 397, in alter_column
    field.rel.to._meta.get_field(field.rel.field_name).column
  File "/home/jb/programs/wnt/zlotKadryRejestracja/south/db/generic.py", line 150, in execute
    cursor.execute(sql, params)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/django/db/backends/util.py", line 34, in execute
    return self.cursor.execute(sql, params)
  File "/home/jb/programs/wnt/zlotKadryRejestracja/django/db/backends/mysql/base.py", line 86, in execute
    return self.cursor.execute(query, args)
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1005, "Can't create table 'rejestracja-2011.#sql-5b2_13c' (errno: 121)")

Attachments

southbug.zip (6.1 KB) - added by jbzdak@… 3 years ago.
Application that shows the error

Change History

Changed 3 years ago by jbzdak@…

Application that shows the error

comment:1 Changed 3 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 1.0

comment:2 Changed 3 years ago by aj

I was struggling with this problem until I noticed that there was no unique constraint on that column so I reset everything and commented out both the forward and backward db.create_unique and db.delete_unique statements and it seems to work nicely. No idea why the constraints weren't created to start with - perhaps it's because I'm using MyISAM tables? Or perhaps it's just because it's MySQL. ;)

comment:3 Changed 2 years ago by anonymous

17 month left. Does South is alive? =\

comment:4 Changed 2 years ago by andrew

Of course it's still alive, this is just low-priority at the moment as there are workarounds and the situation isn't too common. Patches are always welcome.

View

Add a comment

Modify Ticket

Action
as assigned
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.