开发者

MySqlcan't set a nullable column to null

开发者 https://www.devze.com 2022-12-12 21:02 出处:网络
I\'m trying to insert a row into a开发者_开发百科 table named Booklets which has a nullable column BookletSubjectID. The insert is failing because

I'm trying to insert a row into a开发者_开发百科 table named Booklets which has a nullable column BookletSubjectID. The insert is failing because

'BookletSubjectID' cannot be null

Here's my MySQL session copied verbatim. I must be missing something really obvious, but can't see it.

mysql> desc Booklets;
+----------------------+---------------+------+-----+---------+----------------+
| Field                | Type          | Null | Key | Default | Extra          |
+----------------------+---------------+------+-----+---------+----------------+
| BookletID            | int(11)       | NO   | PRI | NULL    | auto_increment |
| MemberID             | int(11)       | NO   | MUL | NULL    |                |
| Name                 | varchar(255)  | YES  |     | NULL    |                |
| Description          | varchar(1000) | YES  |     | NULL    |                |
| RelationshipTypeID   | varchar(12)   | YES  | MUL | NULL    |                |
| RateTypeID           | varchar(2)    | YES  | MUL | NULL    |                |
| PrivTypeID           | varchar(2)    | NO   | MUL | NULL    |                |
| PhotoAlbumID         | int(11)       | YES  | MUL | NULL    |                |
| VideoAlbumID         | int(11)       | YES  | MUL | NULL    |                |
| BookletSubjectTypeID | varchar(2)    | NO   | MUL | NULL    |                |
| BookletSubjectID     | int(11)       | YES  | MUL | NULL    |                |
| Deleted              | tinyint(1)    | NO   |     | 0       |                |
| Credt                | datetime      | NO   |     | NULL    |                |
| Updt                 | datetime      | YES  |     | NULL    |                |
+----------------------+---------------+------+-----+---------+----------------+
14 rows in set (0.00 sec)

mysql> INSERT Booklets (MemberID, Name, PrivTypeID, BookletSubjectTypeID, Deleted, Credt) 
VALUES (546502, 'dddd','pu', 'no', 1, NOW());
ERROR 1048 (23000): Column 'BookletSubjectID' cannot be null

Thanks, Don


It seems that:

If a table has a column which is part of a multi-column primary key then that column cannot be nullable.

See this bug report and its response.

0

精彩评论

暂无评论...
验证码 换一张
取 消