I'm using MySQL version 6.3 and attempted to execute the following syntax:
我正在使用MySQL version 6.3并尝试执行以下语法:
insert into orders(Store_ID, Product_ID, Customer_ID, Quantity, Order_Date)
values (not null, '22','33', '44','2017-03-02');
But keep getting the following error response below:
但是继续得到以下错误响应:
Error Code: 1364. Field 'Orders_ID' doesn't have a default value
I've read several responses on here, many has extensive feedback...could some one provide solutions to this issue without being too extensive?
我在这里读了一些回复,很多都有广泛的反馈……有没有人能在不太广泛的情况下为这个问题提供解决方案?
Thank you
谢谢你!
4 个解决方案
#1
2
This is happening because you are not providing a value for the column, and the column has no default to fall back on.
之所以会出现这种情况,是因为您没有为列提供一个值,并且列没有默认值。
ALTER TABLE orders ALTER COLUMN Orders_ID SET DEFAULT NULL;
Null can be changed to a value you would like.
Null可以更改为您想要的值。
You can do this
你可以这样做
ALTER TABLE orders ALTER COLUMN Orders_ID INTEGER NOT NULL AUTO_INCREMENT;
This will create a new ID on every insert with an increment of 1 each time.
这将在每次插入时创建一个新的ID,每次增加1。
#2
1
Without knowing what the table columns are (i.e. string, int, etc.) as well as what it is that you want to put into the Orders_ID column it's hard to say what you should put however I can try to help you once you reply/update your question. :)
如果不知道表列是什么(即字符串、int等),以及您想要放入Orders_ID列的内容,那么很难说您应该放置什么,但是当您回答/更新您的问题时,我可以尝试帮助您。:)
I'm guessing the column Orders_ID hasn't got AUTO-INCREMENT 1
feature set to it so it doesn't automatically increment and add the new Orders_ID when you insert into the Orders table.
我猜测列Orders_ID没有自动增量1特性集,因此它不会自动增加并添加新的Orders_ID,当您插入到Orders表中时。
#3
1
If you want that you table has a primary key, maybe you can try
如果您希望您的表具有主键,也许您可以尝试一下
ALTER TABLE orders ALTER COLUMN Orders_ID MEDIUMINT NOT NULL AUTO_INCREMENT;
About the value of StoreId, you can't insert NOT NULL
value.
关于StoreId的值,不能插入NOT NULL值。
You can check here Mysql Doc
你可以在这里查看Mysql Doc。
#4
0
you have to put a valid value in your query for the Store_id, as I understand Store_ID is a foreign key from a stores table, so you mus put the id from one store
您必须在查询中为Store_id设置一个有效值,因为我理解Store_id是来自存储表的外键,所以您可以将id从一个存储中放入。
insert into orders (Store_ID, Product_ID, Customer_ID, Quantity, Order_Date)
values ('13', '22','33', '44','2017-03-02');
change 13 for a valid Store_ID
为有效的Store_ID更改13
#1
2
This is happening because you are not providing a value for the column, and the column has no default to fall back on.
之所以会出现这种情况,是因为您没有为列提供一个值,并且列没有默认值。
ALTER TABLE orders ALTER COLUMN Orders_ID SET DEFAULT NULL;
Null can be changed to a value you would like.
Null可以更改为您想要的值。
You can do this
你可以这样做
ALTER TABLE orders ALTER COLUMN Orders_ID INTEGER NOT NULL AUTO_INCREMENT;
This will create a new ID on every insert with an increment of 1 each time.
这将在每次插入时创建一个新的ID,每次增加1。
#2
1
Without knowing what the table columns are (i.e. string, int, etc.) as well as what it is that you want to put into the Orders_ID column it's hard to say what you should put however I can try to help you once you reply/update your question. :)
如果不知道表列是什么(即字符串、int等),以及您想要放入Orders_ID列的内容,那么很难说您应该放置什么,但是当您回答/更新您的问题时,我可以尝试帮助您。:)
I'm guessing the column Orders_ID hasn't got AUTO-INCREMENT 1
feature set to it so it doesn't automatically increment and add the new Orders_ID when you insert into the Orders table.
我猜测列Orders_ID没有自动增量1特性集,因此它不会自动增加并添加新的Orders_ID,当您插入到Orders表中时。
#3
1
If you want that you table has a primary key, maybe you can try
如果您希望您的表具有主键,也许您可以尝试一下
ALTER TABLE orders ALTER COLUMN Orders_ID MEDIUMINT NOT NULL AUTO_INCREMENT;
About the value of StoreId, you can't insert NOT NULL
value.
关于StoreId的值,不能插入NOT NULL值。
You can check here Mysql Doc
你可以在这里查看Mysql Doc。
#4
0
you have to put a valid value in your query for the Store_id, as I understand Store_ID is a foreign key from a stores table, so you mus put the id from one store
您必须在查询中为Store_id设置一个有效值,因为我理解Store_id是来自存储表的外键,所以您可以将id从一个存储中放入。
insert into orders (Store_ID, Product_ID, Customer_ID, Quantity, Order_Date)
values ('13', '22','33', '44','2017-03-02');
change 13 for a valid Store_ID
为有效的Store_ID更改13