2

The webhosting I use has enabled StrictMode for the Databases. All my php scripts now stopped working because they report I haven't defined a default value for some columns.

As I have a lot of columns in a lot of tables, is there a way to set all the columns with "default value = none" with "default value = NULL" ? In this way it won't report me the error anymore.

Of course, If there's another (better) way, I am available for it.

I tried looking on the net, but I couldn't find anything suitable for this case.

OpenStudio
  • 41
  • 1
  • 1
  • 6
  • `none` is not any special value in MySQL of which I'm aware. Can you add sample data which explains what you are trying to do here? – Tim Biegeleisen Mar 27 '19 at 10:35

2 Answers2

1

you can alter column

ALTER TABLE table_name
 MODIFY COLUMN col datatype  DEFAULT null
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63
0

A general approach here which should work for each column causing an error would be to set a default value, and then maybe do an update to backfill records missing a value.

ALTER TABLE yourTable ALTER some_text_column SET DEFAULT 'None';

And here is the update:

UPDATE yourTable SET some_text_column = 'None' WHERE some_text_column IS NULL;

You are not required to do this update, but it might make sense to bring older records missing values in line with what newer records would look like.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360