Mysql表列不能为空 [英] Mysql Table Column Cannot Be Null

查看:497
本文介绍了Mysql表列不能为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含三列的表,分别为Id,Name,Quantity. 看来,当我尝试插入至少包含一个空列的行或试图将列的默认值设置为NULL时,数据库会引发错误. #1048-列数量"不能为空

I have created a table with three columns, Id , Name , Quantity. It appears that when I am trying to insert a row with at least one null column or when i am trying to set the default value of a column to NULL the database throws an error. #1048 - Column 'Quantity' cannot be null

如何设置NULL作为列的有效值?

How can I set NULL as a valid value for a column?

推荐答案

ALTER TABLE mytable MODIFY quantity NUMERIC(20, 2)

NUMERIC(20, 2)替换为您的实际数据类型,但没有NOT NULL约束.

Replace NUMERIC(20, 2) with your actual datatype, but without NOT NULL constraint.

要显示当前的列定义,请运行

To show your current column definitions, run

SHOW CREATE TABLE mytable

mysql(命令行客户端)中

这篇关于Mysql表列不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆