Modify

Ticket #510 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

Generic DatabaseOperations._constraints_affecting_columns assumes all tables are in public schema

Reported by: usefulaccount@… Owned by: andrew
Priority: major Milestone: 0.7.2
Component: commands Version: 0.7
Keywords: Cc:

Description

When running a schemamigration containing:

        db.delete_unique('switchboard_switch', ['host', 'name'])

on a database where the tables are not in the public schema south fails with:

Traceback (most recent call last):
  File "/django/databaseupdates/project-trunk-build.958/project/configs/active_config/manage.py", line 14, in <module>
    execute_manager(settings)
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/django/core/management/base.py", line 218, in execute
    output = self.handle(*args, **options)
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/south/management/commands/migrate.py", line 109, in handle
    ignore_ghosts = ignore_ghosts,
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/south/migration/__init__.py", line 202, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/south/migration/migrators.py", line 220, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/south/migration/migrators.py", line 291, in migrate_many
    result = self.migrate(migration, database)
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/south/migration/migrators.py", line 125, in migrate
    result = self.run(migration)
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/south/migration/migrators.py", line 99, in run
    return self.run_migration(migration)
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/south/migration/migrators.py", line 81, in run_migration
    migration_function()
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/south/migration/migrators.py", line 57, in <lambda>
    return (lambda: direction(orm))
  File "../../switchboard/migrations/0003_auto__add_state__del_field_switch_host__del_field_switch_state__add_fi.py", line 21, in forwards
    db.delete_unique('switchboard_switch', ['host', 'name'])
  File "/django/databaseupdates/project-trunk-build.958/ve/lib/python2.6/site-packages/south/db/generic.py", line 453, 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 switchboard_switch, columns ['host', 'name']

In 0.7, db/generic.py:407, "public" is assumed to always be the schema being used.

Would it be possible to define an alternative schema to be used by south?

Attachments

Change History

comment:1 Changed 4 years ago by usefulaccount@…

Actually, we are using south 0.7.1, not 0.7. Issue is still as described above.

comment:2 Changed 4 years ago by andrew

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

Yes, I see the problem; how are you telling Django to use a different schema in the first place? I can't find the option to do it, even though I'm sure I've done it before.

comment:3 Changed 4 years ago by anonymous

  • Status changed from infoneeded to assigned

We just set our postgres database to create all the tables in a different schema, and I'm pretty sure that they were being found because of the postgres schema search path:
http://www.postgresql.org/docs/8.4/interactive/ddl-schemas.html

We've moved back to just keeping everything in public for now, but it would be a handy fix.

comment:4 Changed 4 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to fixed
  • Milestone changed from 1.0 to 0.7.2

Ah, the problem here is that I need to specify a schema when I do the search, as otherwise if you're running multiple copies of the same table in different schemas, it's going to get very confused.

So, as a workaround for Django not doing this properly, I've made South read the SCHEMA database setting to get the schema (using "public" by default). It's not an official Django setting, but just sling DATABASE_SCHEMA = 'foo' (<=1.1) or 'SCHEMA': 'foo' (1.2) into your settings and it should work. Committed in [efa93ec82673].

View

Add a comment

Modify Ticket

Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.