On 11 May 2010, at 8:09am, Patrick Earl wrote:

> sqlite> begin transaction;
> sqlite>
> sqlite> DROP TABLE "ParkingLotLevel";
> sqlite> DROP TABLE "Car";
> sqlite> DROP TABLE "ParkingLot";
> sqlite>
> sqlite> Commit transaction;
> Error: foreign key constraint failed
> 
> And now, we switch Car and ParkingLotLevel...
> 
> sqlite> begin transaction;
> sqlite>
> sqlite> DROP TABLE "Car";
> sqlite> DROP TABLE "ParkingLotLevel";
> sqlite> DROP TABLE "ParkingLot";
> sqlite>
> sqlite> Commit transaction;
> 
> No error!  Since the constraints are deferred, the order of the table
> drops shouldn't matter, but it clearly does.

Your database schema always has to be valid, even in the middle of a 
transaction.  Keep the above sequence but instead of using DROP TABLE, use 
DELETE FROM to delete all the rows from the table.  I'm guessing you'll find 
that it performs the way you expected.  That's what things like DEFERRED are 
for.

You are doing something weird by renaming, creating and destroying tables when 
you have already set up your schema.  Generally people just mess with records 
inside the tables, they don't move the tables themselves around.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to