Ticket #415 (closed defect: fixed)

Opened 5 years ago

Last modified 4 years ago

adding OneToOneFields creates wrong column name

Reported by: Alexander Clausen <alex@…> Owned by: andrew
Priority: major Milestone: 0.7.1
Component: migrations Version: 0.7
Keywords: Cc:

Description

consider the following model:

class A(models.Model):
    name = models.CharField(max_length=100)

class B(models.Model):
    a_1 = models.OneToOneField(A, related_name="b_1")
    a_2 = models.OneToOneField(A, related_name="b_2", blank=True, null=True)

where

  • A was created,
  • then the app was converted to south (0001),
  • B was added in a migration (without a_2, 0002),
  • and then a_2 was added (0003)

the resulting schema is:

sqlite> .schema footest_a
CREATE TABLE "footest_a" ("id" integer NOT NULL PRIMARY KEY, "name" varchar(100) NOT NULL);
sqlite> .schema footest_b
CREATE TABLE "footest_b" ("a_1_id" integer UNIQUE, "id" integer PRIMARY KEY, "a_2" integer NULL UNIQUE);
sqlite> 

note that a_2 is missing the _id suffix, but a_1 is created allright.

Attachments

models.py (252 bytes) - added by Alexander Clausen <alex@…> 5 years ago.
0001_initial.py (900 bytes) - added by Alexander Clausen <alex@…> 5 years ago.
0002_auto__add_b.py (1.2 KB) - added by Alexander Clausen <alex@…> 5 years ago.
0003_auto__add_field_b_a_2.py (1.3 KB) - added by Alexander Clausen <alex@…> 5 years ago.

Change History

Changed 5 years ago by Alexander Clausen <alex@…>

Changed 5 years ago by Alexander Clausen <alex@…>

Changed 5 years ago by Alexander Clausen <alex@…>

Changed 5 years ago by Alexander Clausen <alex@…>

comment:1 Changed 5 years ago by Alexander Clausen <alex@…>

sorry, of course I should have mentioned that this is on SQLite using south tip

comment:2 Changed 5 years ago by Alexander Clausen <alex@…>

seems to be the same issue as #424

comment:3 Changed 4 years ago by carl@…

Fix for this is in my branch: http://bitbucket.org/carljm/south/changeset/898fefd63e0e

Actual fix is from patch on #424, it's a one-liner. I also fixed the add_columns test so that it fails without this; previously it never actually checked that the proper column was created, just that the add_column call completed without error.

comment:4 Changed 4 years ago by andrew

  • Status changed from new to closed
  • Resolution set to fixed
  • Milestone set to 0.7.1

Thanks, pulled.

Note: See TracTickets for help on using tickets.