Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以配置MySQL,使新添加的列默认允许空值吗?_Mysql - Fatal编程技术网

我可以配置MySQL,使新添加的列默认允许空值吗?

我可以配置MySQL,使新添加的列默认允许空值吗?,mysql,Mysql,我们的开发人员经常忘记在向现有表添加列时指定允许空值。MySQL默认在使用ALTERTABLE命令添加列时,如果不包括Null,则不允许使用Null 有没有办法配置MySQL,使新列允许空值,除非ALTERTABLE命令显式包含NOTNULL 我们使用PHPMyAdmin来更改表,这样就可以通过PHPMyAdmin使所有新添加的字段都允许空值。MySQL的默认行为是alter table命令默认允许空值。它可能与PHPMyAdmin有关 mysql> desc foo; +--------

我们的开发人员经常忘记在向现有表添加列时指定允许空值。MySQL默认在使用ALTERTABLE命令添加列时,如果不包括Null,则不允许使用Null

有没有办法配置MySQL,使新列允许空值,除非ALTERTABLE命令显式包含NOTNULL


我们使用PHPMyAdmin来更改表,这样就可以通过PHPMyAdmin使所有新添加的字段都允许空值。

MySQL的默认行为
alter table
命令默认允许空值。它可能与PHPMyAdmin有关

mysql> desc foo;
+-----------+---------+------+-----+---------+-------+
| Field     | Type    | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+-------+
| id        | int(11) | YES  |     | NULL    |       | 
| client_id | int(11) | YES  |     | NULL    |       | 
| item_id   | int(11) | YES  |     | NULL    |       | 
+-----------+---------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> alter table foo add (a char(1));
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc foo;
+-----------+---------+------+-----+---------+-------+
| Field     | Type    | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+-------+
| id        | int(11) | YES  |     | NULL    |       | 
| client_id | int(11) | YES  |     | NULL    |       | 
| item_id   | int(11) | YES  |     | NULL    |       | 
| a         | char(1) | YES  |     | NULL    |       | 
+-----------+---------+------+-----+---------+-------+
4 rows in set (0.00 sec)

创建新列时,可以指定默认的NULL,如:

ALTER TABLE table
ADD COLUMN column VARCHAR(255) DEFAULT NULL;

很抱歉,你的问题是“我们的开发人员始终如一地把有缺陷的软件交付给生产。我们能改变生产过程来解决那些开发人员的缺陷吗?”无论是否有可能改变生产过程,我希望你会考虑加强软件质量和发布过程。