#27267: Migrations: Need API to drop a foreign key constraint --------------------------------+-------------------- Reporter: Melvyn Sopacua | Owner: nobody Type: Uncategorized | Status: new Component: Migrations | Version: 1.10 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 --------------------------------+-------------------- When Django creates a foreign key constraint it uses a randomly generated string as part of the contraint name at the time it creates it. This has a side-effect that the names of these constraints are different for each database created. The better fix may then also be to get rid of this random string.
When one changes the type of a field that has foreign key references to it, then one cannot migrate the app. Attempts to use RunSQL fail, because as said, each database will have a different contraint name. This is most evident by just trying to create the test database with the following bit in a migration: {{{#!python operations = [ migrations.RunSQL( [ 'ALTER TABLE dpe_dpecharacter DROP CONSTRAINT {}'.format( FKEY_NAME ), ], ] }}} So if the path is chosen not to get rid of the random string, we need a way to find out what the actual name of the foreign key constraint is, preferably wrapped as migrations.DropForeignKey(). The real world case that triggered this, was that initial design used a CharField as primary key, yet limitations in either or both contrib.contenttypes or Mezzanine prevented this from working correctly and an autogenerated primary key had to be used instead. Dropping the primary key is no issue, since it's name is predictable and consistent amonst different incarnations of the database. -- Ticket URL: <https://code.djangoproject.com/ticket/27267> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/057.f4bea139618b73d3a3b97338453fc9d8%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.