Modify

Ticket #473 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

create_primary_key fails on SQLite with invalid SQL generated

Reported by: malcolm.box@… Owned by: andrew
Priority: major Milestone: 0.7.2
Component: databaseapi Version: 0.7.1
Keywords: sqlite Cc:

Description

In the following migration, SQLite fails with pysqlite2.dbapi2.OperationalError?: near "CONSTRAINT": syntax error on the db.create_primary_key line.

def forwards(self, orm):

db.delete_column('polls_event', 'id')
db.rename_column('polls_event', 'uid', 'id')
db.create_primary_key('polls_event', 'id')
db.create_index('polls_event', id?, unique=True)

The generated SQL is:

ALTER TABLE "polls_event" ADD CONSTRAINT "polls_event_pkey" PRIMARY KEY ("id") []

According to http://www.sqlite.org/lang_altertable.html SQLite does not support ALTER TABLE with constraints.

The likely fix is to implement create_primary key by regenerating the table, as per other column changes.

Attachments

patch (2.1 KB) - added by malcolm.box@… 4 years ago.
Patch to implement create_primary_key

Change History

comment:1 Changed 4 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 0.7.2

Agreed, this is clearly something that just hasn't been overridden yet.

Changed 4 years ago by malcolm.box@…

Patch to implement create_primary_key

comment:2 Changed 4 years ago by malcolm.box@…

A patch attached that works for me in the limited testing I've tried.

Almost certainly not the right thing to do as I don't fully understand how this code is supposed to work, nor what the valid restrictions are for primary keys in SQLite.

comment:3 Changed 4 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to fixed

You're right, that wasn't quite the right thing to do, but thanks for trying! I've taken a similar idea but merged it into the main remake_table code, and so this is fixed with [a36afae9f574].

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.