Model first with SQLite
Posted: Wed 23 Feb 2011 12:16
Hi,
I tried to use the model first approach with a SQLite database and when I add a column in a table and then use the option "Update Database with model", the table in the database is deleted and recreated without keeping the rows alive.
I know that SQLite don't allow deleting column on an existing table but in this case, you should create a temporary table, copy all the rows to this table, delete the table, create a new table without the deleted column, copy all the rows from the temporary table and then delete the temporary table.
Here is a sample of code from the web site of SQLite:
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE t1_backup(a,b);
INSERT INTO t1_backup SELECT a,b FROM t1;
DROP TABLE t1;
CREATE TABLE t1(a,b);
INSERT INTO t1 SELECT a,b FROM t1_backup;
DROP TABLE t1_backup;
COMMIT;
Thank you
I tried to use the model first approach with a SQLite database and when I add a column in a table and then use the option "Update Database with model", the table in the database is deleted and recreated without keeping the rows alive.
I know that SQLite don't allow deleting column on an existing table but in this case, you should create a temporary table, copy all the rows to this table, delete the table, create a new table without the deleted column, copy all the rows from the temporary table and then delete the temporary table.
Here is a sample of code from the web site of SQLite:
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE t1_backup(a,b);
INSERT INTO t1_backup SELECT a,b FROM t1;
DROP TABLE t1;
CREATE TABLE t1(a,b);
INSERT INTO t1 SELECT a,b FROM t1_backup;
DROP TABLE t1_backup;
COMMIT;
Thank you