NOT NULLを削除する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
mysql> show fields from site; +-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | user_id | int(11) | NO | MUL | NULL | | | url | varchar(500) | NO | MUL | NULL | | | name | varchar(500) | NO | MUL | NULL | | | category_id | int(11) | NO | MUL | NULL | | | description | text | NO | | NULL | | | published | int(11) | NO | | 1 | | | created_at | datetime | NO | | NULL | | | updated_at | datetime | NO | | NULL | | +-------------+--------------+------+-----+---------+----------------+ 9 rows in set (0.00 sec) mysql> alter table site modify column user_id int; Query OK, 16 rows affected (0.07 sec) Records: 16 Duplicates: 0 Warnings: 0 mysql> show fields from site; +-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | user_id | int(11) | YES | MUL | NULL | | | url | varchar(500) | NO | MUL | NULL | | | name | varchar(500) | NO | MUL | NULL | | | category_id | int(11) | NO | MUL | NULL | | | description | text | NO | | NULL | | | published | int(11) | NO | | 1 | | | created_at | datetime | NO | | NULL | | | updated_at | datetime | NO | | NULL | | +-------------+--------------+------+-----+---------+----------------+ 9 rows in set (0.00 sec) |
NOT NULLを設定する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
mysql> alter table site modify column user_id int not null; Query OK, 16 rows affected (0.06 sec) Records: 16 Duplicates: 0 Warnings: 0 mysql> show fields from site; +-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | user_id | int(11) | NO | MUL | NULL | | | url | varchar(500) | NO | MUL | NULL | | | name | varchar(500) | NO | MUL | NULL | | | category_id | int(11) | NO | MUL | NULL | | | description | text | NO | | NULL | | | published | int(11) | NO | | 1 | | | created_at | datetime | NO | | NULL | | | updated_at | datetime | NO | | NULL | | +-------------+--------------+------+-----+---------+----------------+ 9 rows in set (0.00 sec) |
/