But then you don't have to worry about issues with foreign keys or triggers, or 
the time to copy data, etc. But yes it does "void your warranty" to do so.


pragma writable_schema = true;

begin; --important

update sqlite_master set sql = '..., foreign key () references blah ()...' 
WHERE type = 'table' AND name = 'your table name'; --entire SQL text for the 
table. Be absolutely sure to include type and name in the where clause.

select * from sqlite_master; --examine to make sure you didn't forget the WHERE 
clause and update all tables

commit;

pragma writable_schema = false;

analyze sqlite_master; --forces re-parse so your connection has the changes


-----Original Message-----
From: sqlite-users [mailto:[email protected]] On 
Behalf Of Igor Tandetnik
Sent: Wednesday, September 27, 2017 9:42 AM
To: [email protected]
Subject: Re: [sqlite] CREATE FOREIGN KEY support

On 9/27/2017 9:18 AM, Igor Korot wrote:
> On Wed, Sep 27, 2017 at 7:04 AM, Clemens Ladisch <[email protected]> wrote:
>> Alternatively, if you're feeling adventurous, you can use PRAGMA 
>> writable_schema
>> to modify the table definition in place: 
>> https://stackoverflow.com/a/42970982/11654
> 
> Just curious -  why I should feel adventurous?

If you make a mistake, you can render the schema un-parseable and the database 
un-openable, effectively losing all the data in it.
-- 
Igor Tandetnik


_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to