25.04.2020, 14:57
See indeed Sia's answer. To explain it a bit futher:
You didn't specify this column in the INSERT query. When you don't, the server requires a default value to be set if it also may not be empty (NOT NULL).
Look at this table:
When using the INSERT query:
- You must provide a value for Foo: It may not be null and has no default value.
- You don't have to provide a value for Required: It may not be null but it has a default value. Not specifying Required in an INSERT statement will set it's value to 1
- You don't have to provide a value for Bar. It may be null. If you don't specify it, it will be set to 5.
- You don't have to provide a value for Not_Required. It may be null and it doesn't have a default value. When not specyfing one it will be empty (NULL)
- You must provide a value for spvip. It may not be null and has no default value.
Thus using this query would be valid:
This query would return the error you're currently getting, because spvip has no default value and also is required to have a value:
I hope that clears things up a bit more.
Quote:
Field 'spvip' doesn't have a default value |
Look at this table:
Code:
CREATE TABLE test( Foo INT NOT NULL, Required INT NOT NULL DEFAULT 1, Bar INT DEFAULT 5, Not_Required INT, spvip MEDIUMINT(2) NOT NULL );
- You must provide a value for Foo: It may not be null and has no default value.
- You don't have to provide a value for Required: It may not be null but it has a default value. Not specifying Required in an INSERT statement will set it's value to 1
- You don't have to provide a value for Bar. It may be null. If you don't specify it, it will be set to 5.
- You don't have to provide a value for Not_Required. It may be null and it doesn't have a default value. When not specyfing one it will be empty (NULL)
- You must provide a value for spvip. It may not be null and has no default value.
Thus using this query would be valid:
Code:
INSERT INTO test (Foo, spvip) VALUES (10, 0);
Code:
INSERT INTO test (Foo, Required, Bar, Not_Required) VALUES (10, 0, 6, NULL);