Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to change MySQL column to have the NOT NULL constraint [closed]

I'm trying to change a bunch of columns in my MySQL database to have the NOT NULL constraint using the following:

mysql> ALTER TABLE Jobs CHANGE Date_to_Run Date_to_Run NOT NULL;

I thought that that was how you made such a change but it's giving me a syntax error.
Any ideas on what I'm doing wrong?

EDIT: Here's the error

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL' at line 1

like image 410
avorum Avatar asked Dec 10 '25 23:12

avorum


1 Answers

Here's what's wrong:

ALTER TABLE Jobs CHANGE Date_to_Run Date_to_Run NOT NULL;
                                    ^^^^^^^^^^^ need to specify the data type
                 ^^^^^ it's MODIFY, not CHANGE

Try this:

ALTER TABLE Jobs MODIFY Date_to_Run DATE NOT NULL;

I'm assuming it's type DATE - if not just put in the actual type instead of DATE, then follow it by NOT NULL.

The ALTER TABLE docs are here

like image 169
Ed Gibbs Avatar answered Dec 12 '25 11:12

Ed Gibbs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!