Hmm where did the foreign key go on the 1.2 example?

And I must say that the name for the modelc column is a bit weird.


On Jan 14, 8:13 am, simonb <bno...@gmail.com> wrote:
> I think this tickethttp://code.djangoproject.com/ticket/12386
> identifies a change in the m2m code which breaks backwards
> compatibility.
>
> Consider the following three apps and models:
>
> AppA/models.py:
>
> class ModelA(models.Model):
>     name = models.CharField(max_length=1024, default='', blank=True)
>
> AppB/models.py:
>
> class ModelB(models.Model):
>     name = models.CharField(max_length=1024, default='', blank=True)
>     ma = models.ManyToManyField('AppA.ModelA', blank=True, null=True,
> related_name='mb')
>     mc = models.ManyToManyField('AppC.ModelC', blank=True, null=True,
> related_name='mc')
>
> AppC/models.py:
>
> class ModelC(models.Model):
>     name = models.CharField(max_length=1024, default='', blank=True)
>
> The SQL generated for the m2m fields in AppB is different for Django
> 1.1 and 1.2/trunk. This breaks backwards compatibility.
>
> It seems that in some cases 1.2 names the m2m column 'app.model_id'
> whereas 1.1 uses 'model_id' only - i.e. no 'app.'
>
> This only seems to happen when there are more that one m2m fields in a
> model. Tested with postgresql. The SQL output for the M2M table is
> show below for the different Django versions.
>
> Django 1.1
>
> CREATE TABLE "AppB_modelb_mc" (
>     "id" serial NOT NULL PRIMARY KEY,
>     "modelb_id" integer NOT NULL REFERENCES "AppB_modelb" ("id")
> DEFERRABLE INITIALLY DEFERRED,
>     "modelc_id" integer NOT NULL REFERENCES "AppC_modelc" ("id")
> DEFERRABLE INITIALLY DEFERRED,
>     UNIQUE ("modelb_id", "modelc_id")
> );
>
> Django 1.2
>
> CREATE TABLE "AppB_modelb_mc" (
>     "id" serial NOT NULL PRIMARY KEY,
>     "modelb_id" integer NOT NULL,
>     "appc.modelc_id" integer NOT NULL,
>     UNIQUE ("modelb_id", "appc.modelc_id")
> );
>
> 1.1 = "modelc_id"
> 1.2 = "appc.modelc_id"
>
> I've uploaded a little test project to the ticket which demonstrates.
>
> Simon
-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.


Reply via email to