Created
January 25, 2011 16:15
-
-
Save nrocy/795129 to your computer and use it in GitHub Desktop.
is this 'normal' mysql behaviour? how didn't i notice this before?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> create table wtf ( id int not null auto_increment primary key, expletive varchar(64) not null, incredulity_level int not null, nullable int null ); | |
Query OK, 0 rows affected (0.01 sec) | |
mysql> show create table wtf; | |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |
| Table | Create Table | | |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |
| wtf | CREATE TABLE `wtf` ( | |
`id` int(11) NOT NULL auto_increment, | |
`expletive` varchar(64) NOT NULL, | |
`incredulity_level` int(11) NOT NULL, | |
`nullable` int(11) default NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 | | |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |
1 row in set (0.00 sec) | |
mysql> insert into wtf ( nullable ) values ( '42' ); | |
Query OK, 1 row affected, 2 warnings (0.00 sec) | |
mysql> select * from wtf; | |
+----+-----------+-------------------+----------+ | |
| id | expletive | incredulity_level | nullable | | |
+----+-----------+-------------------+----------+ | |
| 1 | | 0 | 42 | | |
+----+-----------+-------------------+----------+ | |
1 row in set (0.00 sec) | |
Really? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update, this is because MySQL isn't running in strict mode:
Strict mode controls how MySQL handles input values that are invalid or missing. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.)
See: http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables