Dawid Ohia
Dawid Ohia

Reputation: 16445

MariaDB / MySQL adds DEFAULT NULL to column definition, how to change that?

When I create table with this statement:

CREATE TABLE `change_log` (
  `object_id` int(11)
) 

MariaDB creates table change_log which has DEFAULT NULL in it's table definition for object_id column. That is, for the statement:

SHOW CREATE TABLE change_log

it returns:

CREATE TABLE `change_log` (
    `object_id` INT(11) NULL DEFAULT NULL
)

How can I configure mariadb/mysql not to add DEFAULT NULL in this case?

I use MariaDB 10.2.14 on Windows 10

Upvotes: 0

Views: 3065

Answers (2)

Rick James
Rick James

Reputation: 142366

SELECT @@sql_mode;

Do you see STRICT_ALL_TABLES or STRICT_TRANS_MODE?

What happens when you include (or exclude) those from @@sql_mode before the CREATE TABLE? Before the INSERT?

Upvotes: 1

Bernd Buffen
Bernd Buffen

Reputation: 15057

You only must add DEFAULT NULL like this:

CREATE TABLE `change_log` (
  `object_id` int(11) DEFAULT NULL
) ENGINE=InnoDB;

Upvotes: 3

Related Questions