#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          |               Resolution:
     Keywords:                  |             Triage Stage:  Unreviewed
    Has patch:  0               |      Needs documentation:  0
  Needs tests:  0               |  Patch needs improvement:  0
Easy pickings:  0               |                    UI/UX:  0
--------------------------------+--------------------------------------
Changes (by Simon Charette):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Comment:

 Dropping a foreign key from from a field should be done automatically if
 you convert the field to it's underlying datatype.

 For example, if you have a foreign key pointing to a `CharField` named
 `foo` replacing the `ForeignKey` by a `CharField` should be detected as an
 `AlterField` operation when running `makemigrations`. The `AlterField`
 operation should take care of dropping the constraint on `migrate`.

 For example given these initial models.

 {{{#!python
 class Foo(models.Model):
     id = models.CharField(max_length=20, primary_key=True)

 class Bar(models.Model):
     foo = models.ForeignKey(Foo)
 }}}

 Changing your definitions to

 {{{#!python
 class Foo(models.Model):
     pass  # Will use an implicit AutoField

 class Bar(models.Model):
     foo = models.CharField(max_length=20)
 }}}

 Running `makemigrations` should generate a field with an operation similar
 to

 {{{#!python
 AlterField('Bar', 'foo', models.CharField(max_length=20))
 }}}

 And running the migration containing this operation should drop the
 foreign key constraint.

--
Ticket URL: <https://code.djangoproject.com/ticket/27267#comment:1>
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/072.db3f8d8d2e4f686d84f6a92c8109c5e5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to