Is there no other way? Also not quite sure how that would work with CI. sqliterc file but it's a PITA to ask users to do that. Loading resources from /home/johnnyb/.sqlitercĮdit #2: I was able to get it to "stick" by adding the pragma to my. How do I set the foreign_keys pragma and make it stick?Įdit: riffing off the above, and leaving golang out of it: $ sqlite3 -init sqlite3-empty.sql I have also tried the URI based approach, found elsewhere: sqlite3, err := sql.Open("sqlite3", "file:unit_test.db?foreign_keys=on") Everything but the foreign_keys pragma works. Requests := strings.Split(string(file), " ")Įrr = fmt.Errorf("NewSQLite3() error executing seed file sql line: %v\n", err) Syntax The syntax to add a foreign key to an existing table in SQLite is: PRAGMA foreignkeysoff BEGIN TRANSACTION ALTER TABLE table1 RENAME TO table1old CREATE TABLE table1 ( column1 datatype NULL NOT NULL, column2 datatype NULL NOT NULL. Note that I am loading the sql creation script as part of a go unit test apparatus setup: sqlite3, err := sql.Open("sqlite3", "unit_test.db")Įrr = fmt.Errorf("NewSQLite3() error creating db connection: %w", err)įile, err := ioutil.ReadFile("sqlite3-empty.sql")Įrr = fmt.Errorf("NewSQLite3() error opening seed file: %w", err) sqliterc file? Or from an environment variable? Is there a away to set this pragma in my. If you want SQLite to enforce foreign key constraints specified on your tables, you must enable them with. Loading resources from /home/me/.sqliterc Foreign key constraints are not checked by default. However, if I load the database file created by the sql file above, it doesn't stick: $ sqlite3 unit_test.db Loading resources from sqlite3-empty.sql When I load the sql file using -init it looks good: $ sqlite3 -init sqlite3-empty.sql In that sql file, I attempt to enforce foreign_keys with the pragma: PRAGMA foreign_keys = on - also 1, true I have created an SQL file that loads into sqlite3 and creates a bunch of tables for me.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |