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
SqLite tries to insert NULL values into NOT NULL fields. #4715
Comments
Please include the generated SQL for the failing queries. |
I'm -1 on this. I suspect MySQL is passing the tests because it silently ignores not-null constraints and automatically substitutes them with empty strings (or, for a date field with Basically, MySQL is wrong here; after all, marking a field as CakePHP could instead automatically generate and perform validation-rules based on the schema and invalidate the record before attempting to save it to the database. |
For additional reading on MySQL behaving badly, it is possible to make MySQL more compliant with the standards by setting the Server SQL Mode. Documentation in this can be found here; http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html |
MySQL is the worst. You should get the SQL you write and deal with the consequences. I suspect that both postgres and sqlerver would fail in similar ways. |
The queries run are:
and debugging the Connection object:
So as you can see I don't even touch that "first_name" field etc. |
The error was;
The insert query does not contain a value for |
Closing as the queries seem to be doing what they should and are not responsible for inserting null values in the database, which was our suspicion. Please fix your code so it saves all required columns for your schema. |
Almost correct. But it helped me to track down the problem. It was the upgraded 2.x fixture.
Which then breaks SqLite.
seems to resolve the issue. So I think the ORM should throw an exception here instead when someone tries to use |
so how do you propose a schema where the column needs to be not null and if the column is missing you get the error? It looks to me that |
Closing as related PR #4731 is opened. |
Resolves cakephp/docs/cakephp#4715
When saving just city field this occurs:
As you can see from https://travis-ci.org/dereuromark/cakephp-geo/builds/36043030 the tests for Mysql pass just fine.
Also, when debugging the input prior to saving it is clear that non of the fields in question are marked as dirty or are touched in any way. The sql going into the Connection class looks fine, as well.
So for some reason SqLite takes all schema fields that are not part of the created record and tries to insert them as NULL - which will fail for all NOT NULL fields, of course.
Maybe it should check the schema and apply an empty string where necessary instead.
The text was updated successfully, but these errors were encountered: