Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.6 sqlite some tests has been broken #23103

Closed
webmake opened this issue Feb 10, 2018 · 11 comments
Closed

5.6 sqlite some tests has been broken #23103

webmake opened this issue Feb 10, 2018 · 11 comments

Comments

@webmake
Copy link
Contributor

webmake commented Feb 10, 2018

  • Laravel Version: 5.6.3
  • PHP Version: 7.1.12
  • Database Driver & Version: sqlite

Description:

I tried to migrate from 5.5.32 to 5.6.3 version, but some of tests (1.6% of all tests) started to fail with very weird error:
Integrity constraint violation: 19 CHECK constraint failed

Is there any change was made to sqlite, like strict mode or something like that?

error occurs on very primitive line:

        factory(Cart::class)->create();
Illuminate\Database\QueryException : SQLSTATE[23000]: Integrity constraint violation: 19 CHECK constraint failed: carts (SQL: insert into "carts" ("id", "name", "slug", "type", "price", "time", "order", "published", "updated_at", "created_at") values (2772147016, Alfreda Moen, fake_slug, random, 13831, 9211, 169, 1, 2018-02-10 00:44:47, 2018-02-10 00:44:47))
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Connection.php:459
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Connection.php:411
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php:32
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2188
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1281
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:725
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:690
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:553
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:172
 /vagrant/vendor/laravel/framework/src/Illuminate/Support/Collection.php:339
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:173
 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:151
 /vagrant/Modules/Cart/Tests/Http/Controllers/StoreControllerTest.php:101

There is no relations in that table, so I don't have any ideas what can arise such error..

http://www.sqlite.org/opcode.html#Halt maybe this can help

@lancepioch
Copy link
Contributor

What's your DB schema for that table?

@webmake
Copy link
Contributor Author

webmake commented Feb 11, 2018

From first migration:

        Schema::create('carts', function(Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->enum('slug', Slug::enum());
            $table->enum('type', CartType::enum());
            $table->unsignedSmallInteger('price');
            $table->unsignedSmallInteger('time');
            $table->unsignedTinyInteger('order');

            $table->timestamps();
            $table->unique(['type', 'order']);
        });

and later was alter file:

        Schema::table('carts', function(Blueprint $table) {
            $table->boolean('published')->default(false);
            $table->softDeletes();
        });

@lancepioch
Copy link
Contributor

Can you list out the Slug::enum() and CartType::enum(), that's possibly where the check constraint error is coming from.

@webmake
Copy link
Contributor Author

webmake commented Feb 11, 2018

There is nothing except simple array of values, ex.: ['slug1', 'slug2'], they are unique, so no duplicated values. As I told it worked in 5.5, even since 5.3 version those tests exists, this could not happen suddenly while code basis didn't changed :/

@lancepioch
Copy link
Contributor

lancepioch commented Feb 11, 2018

The error shows your SQL insert statement which includes inserting "fake_slug" into the slug column and "random" into the type column. Neither of those match "slug1" or "slug2".

Because SQLite doesn't natively support enums, I'm assuming Laravel uses CHECK constraints instead to limit the columns.
Your errors are returned directly by SQLite saying that the CHECK constraints have failed.
Unless you manually added CHECK constraints yourself, I don't see where else they could come from.

@webmake
Copy link
Contributor Author

webmake commented Feb 11, 2018

I didn't provided full list of slug enums, only some of them to imagine values, so faker chose random slug value of all slug posible values, so there is no doubt that created schema with one value but inserting other, I am working with same set.
This still doesn't explain why worked before. I can try to reset till 5.6.1 version, maybe there is working version.

@webmake
Copy link
Contributor Author

webmake commented Feb 11, 2018

Even 5.6.0 throws same error.

Well, I changed really not existing fake_slug to slug1, and it works.. Strange why it worked up to 5.6 laravel.. We had previously problem by setting DB::statement('PRAGMA foreign_keys = ON;'); when creating child relations without parent, so deleted foreign_keys option, but as I see it has no difference if on or off with fake_slug

@webmake
Copy link
Contributor Author

webmake commented Feb 11, 2018

I have found problem and not...

protected function typeEnum(Fluent $column)

within #22109

This place has changed

@mfn
Copy link
Contributor

mfn commented Feb 12, 2018

Indeed, was introduced in #22109

@andreich1980
Copy link
Contributor

For me the problem was with a case of a value I fill a enum-field with.

$table->enum('state', ['NEW', 'WORKING', 'CLOSED'])
	->default('NEW')
	->index();

and in a factory

'state' => 'new', // it has to be NEW

@staudenmeir
Copy link
Contributor

@laurencei Can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants