MySQL#1364-字段'column_name'没有默认值-无法插入数据库 [英] MySQL #1364 - Field 'column_name' doesn't have a default value - Can't insert into DB

查看:187
本文介绍了MySQL#1364-字段'column_name'没有默认值-无法插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的MySQL数据库移到了新服务器上,这给了我以前在MySQL上遇到过的一些问题. 我的表列设置为默认=>无",并且我的表已根据数据类型生成默认值.但是现在当我尝试插入表中时,我收到此错误消息: #1364-字段'column_name'没有默认值",然后表中没有任何内容.

I recently moved my MySQL database to a new server and it has given me some problems i have newer experienced with MySQL before. My table columns are set to "Default => None" and my table has been generating the default value depending on the Datatype. But now when i try to insert into a table i'm getting this error message: "#1364 - Field 'column_name' doesn't have a default value" and then nothing is inserted into the table.

我该怎么做才能使默认"选择它自己的值?

What can i do to make the "Default" choose it's own value?

推荐答案

由于字段"column_name"(可能还有其他字段)被检查为"NOT NULL",因此它没有明确地保存到数据库中.这意味着该字段的值必须是非NULL的值(NULL-完全没有数据)

It's not saving into database definetly because the field 'column_name' (and maybe some others) is checked as "NOT NULL". It means that the value of that field must be something other that NULL (NULL - no data at all)

将字段标记为非null通常是一种确保某些数据始终存在于字段中的好方法.根据您的需要,您也可以将其标记为NULL,这样它就永远不会抛出错误,并且可以保存到DB中,而无需在指定字段中插入任​​何内容.

Marking fields as not null is usually a great way to ensure that some data will always be present in the field. Depending on your needs, you can also mark it as NULL so it will never throw an error and will save into DB without the need for anything to be inserted into a specified field.

这意味着您有2个选择:

It means you have 2 options:

  1. 将您的字段标记为NULL(首先检查您的字段是否需要具有某些值).

  1. Mark your field as NULL (first check if your field is required to have some value or not).

更改表your_table 更改列your_field your_field VARCHAR(250)NULL;

ALTER TABLE your_table CHANGE COLUMN your_field your_field VARCHAR(250) NULL;

向该字段添加默认值,因此,如果插入时未提供任何数据,它将放置您定义的内容. 例如:

Add a default value to the field so if no data is provided on insert, it will put something you defined. For example:

更改表your_table更改列your_field your_field VARCHAR(250)NOT NULL缺省'some_default_value';

ALTER TABLE your_table CHANGE COLUMN your_field your_field VARCHAR(250) NOT NULL DEFAULT 'some_default_value';

当然,将您的字段类型与要更改的字段相匹配.

And ofcourse match your field type to the field your are going to change.

这篇关于MySQL#1364-字段'column_name'没有默认值-无法插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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