Modify

Ticket #205 (closed defect: fixed)

Opened 5 years ago

Last modified 3 years ago

add_column fails for unique ForeignKey or OneToOneField

Reported by: john.firebaugh@… Owned by: andrew
Priority: major Milestone: 0.6
Component: databaseapi Version: 0.6-pre
Keywords: Cc:

Description

    def test_add_unique_fk(self):
        """
        Test adding a ForeignKey with unique=True or a OneToOneField
        """
        db.create_table("test_add_unique_fk", [
            ('spam', models.BooleanField(default=False))
        ])
        db.start_transaction()
        
        db.add_column("test_add_unique_fk", "mock1", models.ForeignKey(db.mock_model('Mock', 'mock'), null=True, unique=True))
        db.add_column("test_add_unique_fk", "mock2", models.OneToOneField(db.mock_model('Mock', 'mock'), null=True))
        
        db.rollback_transaction()
        db.delete_table("test_add_unique_fk")

With a sqlite database, this produces:

OperationalError: table test_add_unique_fk has no column named mock1

when trying to create a unique index on column 'mock1'. It should instead be creating the unique index on column 'mock1_id'.

Attachments

Change History

comment:1 Changed 5 years ago by andrew

  • Status changed from new to closed
  • Resolution set to fixed
  • Version set to Mercurial tip
  • Component changed from commands to databaseapi
  • Milestone set to 0.6

Fixed in [da117a13a6cd].

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.