nadj
1 month ago
224
4
Testing

Testing with sqlite CONSTRAINT name issue

Posted 1 month ago by nadj

I'm updating from laravel 5.8 to 6 the issue is that all of my tests, that are depending on the database, are failing. The error I'm getting is:

Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 near "0": syntax error (SQL: CREATE TABLE posts (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, type_id INTEGER NOT NULL, author_id INTEGER NOT NULL, status INTEGER NOT NULL, "order" INTEGER DEFAULT NULL, published DATETIME NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, template VARCHAR(255) DEFAULT NULL COLLATE BINARY, CONSTRAINT 0 FOREIGN KEY (type_id) REFERENCES post_types (id) ON UPDATE NO ACTION ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT 1 FOREIGN KEY (author_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE))

For some reason the sql generated from the migration creates CONSTRAINT 0, CONSTRAINT 1 which is not a valid constraint name in sqlite. Is there a fix for this? I'm struggling with it for a quite long time :(

Please sign in or create an account to participate in this conversation.