Ошибка 1364 mysql workbench

In this article, we will discuss why Error 1364 occurs and how to resolve it. 

Table of Contents

  • Introduction
  • Error code 1364 resolution with AUTO_INCREMENT
  • Error code 1364 resolution with DEFAULT value

Introduction

MySQL server throws the Error 1364 if the query or statement tries to insert a row without a value for a particular column defined as NOT NULL. We can say that the absence of a NOT NULL column value during insertion causes this error to be thrown by the MySQL server. 

Error 1364  indicates that the value of the particular field should be something other than NULL. One way to resolve the error forever is to make the column as DEFAULT NULL in table definition but if that does not meet your requirement, let us see some ways to fix this error in the below sections.

We will be creating a sample table employee_details for illustration of the concept.

#create the table employee_details
 CREATE TABLE employee_details(
  emp_id int ,
  emp_enroll_no varchar(255) NOT NULL,
  emp_firstName varchar(255) DEFAULT NULL,
  emp_lastName varchar(255) DEFAULT NULL,
  primary key(emp_id)
);

Here, the column emp_id and emp_enroll_no both cannot be NULL.

DESC employee_details;

Output:-

image_1

Error code 1364 resolution with AUTO_INCREMENT

In this section, we will recreate error 1364 and will fix it using the AUTO_INCREMENT keyword. AUTO_INCREMENT in MySQL assigns a numeric value to a column starting from 1 (when another starting number not specified) and then increments the value by 1 for consecutive inserts.

Let us try to insert a row without specifying any value for column emp_id.

INSERT INTO employee_details (emp_enroll_no,emp_firstName,emp_lastName) VALUES("1-N","Henry","Smith");

Action Output:-

image_2

Since we did not specify any value for emp_id in the insert statement, the output in image_2 shows that the error 1364 is thrown with the message response: Error Code: 1364. Field ’emp_id’ doesn’t have a default value.

Observe the below ALTER query for the solution. Any insert happening after executing the below statement will assign a value to emp_id starting with 1 and incremented by 1 in successive inserts. 

ALTER TABLE employee_details MODIFY emp_id int NOT NULL AUTO_INCREMENT;

Action Output:-

image_3

Let us again try to execute the insert statement.

INSERT INTO employee_details (emp_enroll_no,emp_firstName,emp_lastName) VALUES("1-N","Henry","Smith");

Action Output:-

image_4

Insert is successful this time.

SELECT * FROM employee_details;

Output:-

image_5

Error code 1364 resolution with DEFAULT value

This section will recreate error 1364 and fix it by assigning a DEFAULT value to the column.

Let us try to insert a row without specifying any value for column emp_enroll_no.

 INSERT INTO employee_details (emp_id, emp_firstName, emp_lastName) VALUES(2, "Richa", "Johnson");

Action Output:-

image_6

Since we did not specify any value for emp_enroll_no in the insert statement, the output in image_6 shows that the error 1364 is thrown with the message response: Error Code: 1364. Field ’emp_enroll_no’ doesn’t have a default value.

Observe the below ALTER query for the solution. Here, we will give a default value to the column emp_enroll_no such that if any insert happens without any value for emp_enroll_no, a default value “N-N” will be inserted.

ALTER TABLE employee_details MODIFY emp_enroll_no varchar(255) NOT NULL DEFAULT "N-N";

Action Output:-

image_7

Let us again try to execute the same insert statement.

INSERT INTO employee_details (emp_id, emp_firstName, emp_lastName) VALUES(2, "Richa", "Johnson");

Action Output:-

image_8

Insert is successful this time.

SELECT * FROM employee_details;

Output:-

image_9

The output in image_9 shows that a default value of “N-N” was inserted in second row.

READ MORE:

  • MySQL: Error 1264 Out of range value for a column [Solved]

We hope this article helped you understand and resolve Error 1364 in MySQL. Good Luck!!!

MySQL Error 1364 can now be fixed with any of these methods provided in this article. At Bobcares, as part of our MySQL Support Service, we answers all MySQL inquiries, large or small.

When will we see ‘MySQL Error 1364’?

If a query or statement tries to insert/update a record without a value for a specific column that is NOT NULL, MySQL server throws the Error 1364. We can say that the MySQL server throws this error because there wasn’t a NOT NULL column value during the insertion process.

This exception only occurs when using MySQL in Strict mode. We can find out easily what mode the MySQL server is running in by executing the following command:

SELECT @@sql_mode;

How To Fix MySQL Error 1364?

Let’s see the ways our Support team suggests to fix this error.

  1. Logic Solution: When trying to insert a record, the value will be null but the error won’t be thrown if you provide a value for the field that is causing the exception or specify that the field can be null. For instance, with a column that cannot be null, the following query would throw the exception.
    INSERT INTO user (column_a, column_b) VALUES ("Value First Column", NULL);

    Now we alter the column to make the column nullable.

    ALTER TABLE YourTable MODIFY column_b VARCHAR(255) DEFAULT NULL;

    The MySQL Error 1364 will not appear again.

  2. Server Side Solution: Uninstalling MySQL’s strict mode is a simple solution. By changing the sql_mode setting to an empty string or by removing the STRICT_TRANS_TABLES option that puts MySQL in Strict Mode and enabling the NO_ENGINE_SUBSTITUTION mode, we can disable the strict mode in MySQL’s configuration file (my.ini in Windows or my.cnf in Linux).
    [mysqld]
    sql-mode=""
    # Or
    # sql-mode="NO_ENGINE_SUBSTITUTION"
    

    Now save the changes, restart MySQL, and the MySQL Error 1364 won’t show up again.

  3. Using AUTO_INCREMENT: When no other starting number is specified, MySQL’s AUTO INCREMENT function assigns a numeric value to each column starting at 1 and increases that value by 1 with each additional insert. Let’s take an example:
    CREATE TABLE employee_details(
      emp_id int ,
      emp_enroll_no varchar(255) NOT NULL,
      emp_firstName varchar(255) DEFAULT NULL,
      emp_lastName varchar(255) DEFAULT NULL,
      primary key(emp_id)
    );

    Here the columns, emp_id and emp_enroll_no both cannot be NULL. Then insert a record with the command without specifying any value for column emp_id.

    INSERT INTO employee_details (emp_enroll_no,emp_firstName,emp_lastName) VALUES("1-N","Henry","Smith");

    Since we left emp_id blank in the insert statement, the output reveals the MySQL Error 1364 with the following message response: Error Code 1364. So we can fix it by ALTER query. Any insert after executing the below statement will assign a value to emp_id starting with 1 and increments by 1 in successive inserts.

    ALTER TABLE employee_details MODIFY emp_id int NOT NULL AUTO_INCREMENT;

    Now executing the insert statement again without specifying any value for column emp_id will result in a successful insert this time.

[Looking for a solution to another query? We are just a click away.]

Conclusion

To conclude, Our Support team briefly explains about the MySQL Error 1364. The article also includes some of the simple solutions to fix the error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

If you’re getting MySQL error 1364, that reads something like Field 'column_name' doesn't have a default value, where column_name is the name of a column in your table, it’s probably because you’re trying to perform an operation that retrieves the column’s default value, but it doesn’t have a default value.

This can happen when the column is set to NOT NULL and hasn’t been defined with an explicit default value.

The solution to this issue will depend on what we’re trying to do. Below are examples of how to fix this error.

Example of Error

Here are some scenarios that will produce the error.

Suppose we create the following table:

CREATE TABLE Products (
    ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
    ProductName varchar(255) NOT NULL,
    ProductDescription varchar(1000),
    Price decimal(8,2)
);

And we now try to get the default value for the ProductName column:

SELECT 
    DEFAULT(ProductName)
FROM Products;

Result:

ERROR 1364 (HY000): Field 'ProductName' doesn't have a default value

It returned error 1364. The reason for this is because the ProductName column doesn’t have a default value set and it’s specified as NOT NULL.

Here’s another scenario that will produce the same error:

INSERT INTO Products ( ProductId )
VALUES ( 1 );

Result:

ERROR 1364 (HY000): Field 'ProductName' doesn't have a default value

In this case, I tried to insert a row into the table, but I didn’t specify a value for the ProductName column. MySQL returned an error because the column has no default value and it’s a NOT NULL column.

Solution 1 – Provide a Value

If we get the error when trying to insert data, one solution is to ensure we provide a value for the column.

So for example, we could change the above INSERT statement to the following:

INSERT INTO Products ( ProductId, ProductName )
VALUES ( 1, 'Hammer' );

Result:

Query OK, 1 row affected (0.00 sec)

This time the row was inserted.

Note that I didn’t provide any values for the ProductDescription and Price columns, but they didn’t cause an error.

The reason those two columns didn’t produce an error is because they are nullable columns (i.e. they aren’t defined as NOT NULL). When we define a column without a NOT NULL clause, MySQL implicitly adds an explicit DEFAULT clause to the column.

We can verify this by using SHOW CREATE TABLE to check the table’s definition:

SHOW CREATE TABLE Products;

Result:

+----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table    | Create Table                                                                                                                                                                                                                                                                                                        |
+----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Products | CREATE TABLE `Products` (
  `ProductId` int NOT NULL AUTO_INCREMENT,
  `ProductName` varchar(255) NOT NULL,
  `ProductDescription` varchar(1000) DEFAULT NULL,
  `Price` decimal(8,2) DEFAULT NULL,
  PRIMARY KEY (`ProductId`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

We can see that the table’s definition has DEFAULT clauses against both the ProductDescription column and the Price column, even though we didn’t specify those DEFAULT clauses when we created the table. MySQL added the clauses due to the fact that they were nullable columns. But it didn’t add any DEFAULT clauses to our ProductName column, because we explicitly defined that column as NOT NULL. As mentioned, MySQL doesn’t implicitly add any DEFAULT clauses to NOT NULL columns. It’s up to us to specify such a clause.

Solution 2 – Use the IGNORE Clause

Another option is to use the IGNORE clause. The IGNORE clause will ignore the error and insert the row anyway. In this case it will insert the implicit default value for the data type, and downgrade the error to a warning.

Example:

INSERT IGNORE INTO Products ( ProductId )
VALUES ( 2 );

Result:

Query OK, 1 row affected, 1 warning (0.00 sec)

This time we didn’t get an error. Instead, one row was inserted and we got a warning.

Let’s check the warning:

SHOW WARNINGS;

Result:

+---------+------+--------------------------------------------------+
| Level   | Code | Message                                          |
+---------+------+--------------------------------------------------+
| Warning | 1364 | Field 'ProductName' doesn't have a default value |
+---------+------+--------------------------------------------------+

The warning tells us the same thing that the error message told us – that the field doesn’t have a default value. However, in this case the row was actually inserted.

Let’s take a look at the table:

SELECT * FROM Products;

Result:

+-----------+-------------+--------------------+-------+
| ProductId | ProductName | ProductDescription | Price |
+-----------+-------------+--------------------+-------+
|         1 | Hammer      | NULL               |  NULL |
|         2 |             | NULL               |  NULL |
+-----------+-------------+--------------------+-------+

We now have two rows in the table. Given we provided a value for just one column, MySQL inserted the implicit default values for the other three columns. Specifically, it inserted an empty string in the ProductName column, and NULL into the other two columns.

You may be wondering why the ProductName column has an empty string and the ProductDescription column has NULL, despite them both being string types?

You may recall that MySQL generated an explicit DEFAULT NULL clause for the ProductDescription column (and for the Price column) when we defined those columns without a NOT NULL constraint. That’s why MySQL inserted NULL into those columns now.

But for the ProductName column, we explicitly defined that column as NOT NULL, which meant that MySQL didn’t generate a DEFAULT clause for that column. And now that we are trying to insert data without a value, MySQL inserts the implicit default value for the data type (which is an empty string for string data types).

Solution 3 – Disable Strict Mode

We can alternatively disable strict SQL mode. By doing this, we’ll get the same result as the previous example without having to use the IGNORE keyword.

First, let’s check our current SQL mode:

SELECT @@SESSION.sql_mode;

Result:

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

We can see that STRICT_TRANS_TABLES is included in my list of SQL modes. This enables strict mode. It would be the same if our SQL mode contained STRICT_ALL_TABLES. Both of those enable strict mode.

To disable strict mode, we can either remove these specific settings from our SQL mode, or we can simply explicitly set our SQL mode to be either blank or to have the settings that we want to keep.

Example:

SET @@sql_mode = sys.list_drop(@@sql_mode, 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO');

Result:

Query OK, 0 rows affected (0.00 sec)

In this case I removed four settings. The other three settings are related to strict mode, and so I decided to drop them from the list.

Here’s what our SQL mode looks like now:

SELECT @@SESSION.sql_mode;

Result:

ONLY_FULL_GROUP_BY,NO_ENGINE_SUBSTITUTION

So I’ve disabled strict mode.

Now let’s try inserting another row like we did above (but this time without the IGNORE clause):

INSERT INTO Products ( ProductId )
VALUES ( 3 );

Result:

Query OK, 1 row affected, 1 warning (0.01 sec)

We get the same outcome that we got when we used the IGNORE clause.

The warning is the same:

SHOW WARNINGS;

Result:

+---------+------+--------------------------------------------------+
| Level   | Code | Message                                          |
+---------+------+--------------------------------------------------+
| Warning | 1364 | Field 'ProductName' doesn't have a default value |
+---------+------+--------------------------------------------------+

Let’s check the data:

SELECT * FROM Products;

Result:

+-----------+-------------+--------------------+-------+
| ProductId | ProductName | ProductDescription | Price |
+-----------+-------------+--------------------+-------+
|         1 | Hammer      | NULL               |  NULL |
|         2 |             | NULL               |  NULL |
|         3 |             | NULL               |  NULL |
+-----------+-------------+--------------------+-------+

We get the same outcome as far as the data insert goes. The ProductName contains an empty string, and the ProductDescription and Price columns contain NULL.

Solution 4 – Remove the NOT NULL Clause

If we find ourselves trying to implement solutions that override the NOT NULL clause, then perhaps the column really shouldn’t have a NOT NULL clause in the first place.

If we determine that the column shouldn’t be NOT NULL, then we should remove NOT NULL from its definition.

Example:

ALTER TABLE Products 
MODIFY ProductName varchar(255) NULL;

Result:

Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

Here, I explicitly used NULL to define the column as nullable, but I could have omitted this if I wanted. Either way, the column would still have been defined as nullable.

Let’s now use SHOW CREATE TABLE to take a look at the table definition:

SHOW CREATE TABLE Products;

Result:

+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table    | Create Table                                                                                                                                                                                                                                                                                                            |
+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Products | CREATE TABLE `Products` (
  `ProductId` int NOT NULL AUTO_INCREMENT,
  `ProductName` varchar(255) DEFAULT NULL,
  `ProductDescription` varchar(1000) DEFAULT NULL,
  `Price` decimal(8,2) DEFAULT NULL,
  PRIMARY KEY (`ProductId`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

We can see that the ProductName column is now defined as DEFAULT NULL.

Let’s insert another row:

INSERT INTO Products ( ProductId )
VALUES ( 4 );

Result:

Query OK, 1 row affected (0.00 sec)

OK, success.

Now let’s look at the data:

SELECT * FROM Products;

Result:

+-----------+-------------+--------------------+-------+
| ProductId | ProductName | ProductDescription | Price |
+-----------+-------------+--------------------+-------+
|         1 | Hammer      | NULL               |  NULL |
|         2 |             | NULL               |  NULL |
|         3 |             | NULL               |  NULL |
|         4 | NULL        | NULL               |  NULL |
+-----------+-------------+--------------------+-------+

This time the ProductName column contains NULL instead of an empty string. That’s because the column was defined with an explicit DEFAULT NULL when we defined it as NULL.

Solution 5 – Add a DEFAULT Clause

If we simply add our own DEFAULT clause to our column/s, we would save ourselves the trouble of having to decide which of the above solutions we want to implement, and we wouldn’t have to make do with the default values that MySQL uses when it implicitly adds the DEFAULT clause.

Let’s redefine our table with our own DEFAULT clause:

ALTER TABLE Products 
MODIFY ProductName varchar(255) NOT NULL DEFAULT 'N/A';

Result:

Query OK, 4 rows affected, 1 warning (0.01 sec)
Records: 4  Duplicates: 0  Warnings: 1

It worked, but we got a warning.

Let’s check the warning:

SHOW WARNINGS;

Result:

+---------+------+--------------------------------------------------+
| Level   | Code | Message                                          |
+---------+------+--------------------------------------------------+
| Warning | 1265 | Data truncated for column 'ProductName' at row 4 |
+---------+------+--------------------------------------------------+

The data in our ProductName column at row 4 has been truncated. In our case, this isn’t a problem – you’ll recall that this contained NULL.

Let’s take a look at the data anyway:

SELECT * FROM Products;

Result:

+-----------+-------------+--------------------+-------+
| ProductId | ProductName | ProductDescription | Price |
+-----------+-------------+--------------------+-------+
|         1 | Hammer      | NULL               |  NULL |
|         2 |             | NULL               |  NULL |
|         3 |             | NULL               |  NULL |
|         4 |             | NULL               |  NULL |
+-----------+-------------+--------------------+-------+

So it no longer contains NULL (but it doesn’t contain our new default value N/A either).

Anyway, let’s insert another row:

INSERT INTO Products ( ProductId )
VALUES ( 5 );

Result:

Query OK, 1 row affected (0.00 sec)

And let’s check the data:

SELECT * FROM Products;

Result:

+-----------+-------------+--------------------+-------+
| ProductId | ProductName | ProductDescription | Price |
+-----------+-------------+--------------------+-------+
|         1 | Hammer      | NULL               |  NULL |
|         2 |             | NULL               |  NULL |
|         3 |             | NULL               |  NULL |
|         4 |             | NULL               |  NULL |
|         5 | N/A         | NULL               |  NULL |
+-----------+-------------+--------------------+-------+

This time the default value of N/A was inserted into the ProductName column, as expected.

So Which Solution to Use?

The examples on this page are just that – examples. In the real world, columns like the ProductName column shouldn’t really be left blank or set to a generic default value. Such columns are usually set to NOT NULL for good reason, and overriding this would compromise data integrity. Imagine if you had a database full of products with no name or with the same (default) name. Therefore, solution 1 above (i.e. insert an explicit value for the column) will usually be the best solution for such columns.

However, if a business rule states that there should be a default setting, then that could be a good time to explicitly implement a default clause.

And if the column is more of an optional column, it may be fine for it to be nullable and/or to have a default value.

My table looks like

create table try ( name varchar(8), CREATED_BY varchar(40) not null);

and then I have a trigger to auto populate the CREATED_BY field

create trigger autoPopulateAtInsert BEFORE INSERT on try for each row set new.CREATED_BY=user();

When I do an insert using

insert into try (name) values ('abc');

the entry is made in the table but I still get the error message

Field 'CREATED_BY' doesn't have a default value Error no 1364

Is there a way to suppress this error without making the field nullable AND without removing the triggfer? Otherwise my hibernate will see these exceptions ( even though the insertions have been made) and then application will crash.

Miklos Aubert's user avatar

asked Mar 15, 2013 at 17:41

kk1957's user avatar

Open phpmyadmin and goto ‘More’ Tab and select ‘Variables’ submenu.
Scroll down to find sql mode.
Edit sql mode and remove ‘STRICT_TRANS_TABLES’
Save it.

answered Oct 19, 2014 at 15:41

Nilesh Dhangare's user avatar

Nilesh DhangareNilesh Dhangare

1,0671 gold badge7 silver badges2 bronze badges

6

In phpmyadmin, perform the following:

select @@GLOBAL.sql_mode

In my case, I get the following:

ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES ,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

Copy this result and remove STRICT_TRANS_TABLES. Then perform the following:

set GLOBAL sql_mode='ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

answered Aug 26, 2016 at 7:43

Kamil's user avatar

KamilKamil

9761 gold badge8 silver badges18 bronze badges

5

Set a default value for Created_By (eg: empty VARCHAR) and the trigger will update the value anyways.

create table try ( 
     name varchar(8), 
     CREATED_BY varchar(40) DEFAULT '' not null
);

zardilior's user avatar

zardilior

2,83025 silver badges30 bronze badges

answered Mar 15, 2013 at 17:47

KinSlayerUY's user avatar

KinSlayerUYKinSlayerUY

1,91317 silver badges22 bronze badges

8

When I had this same problem with mysql5.6.20 installed with Homebrew, I solved it by going into my.cnf

nano /usr/local/Cellar/mysql/5.6.20_1/my.cnf

Find the line that looks like so:

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

Comment above line out and restart mysql server

mysql.server restart

Error gone!

answered Sep 15, 2014 at 13:37

Kingsley Ijomah's user avatar

Run mysql console:

mysql -u your_username -p

, select database:

USE your_database;

and run (also from mysql console):

SET GLOBAL sql_mode='';

That will turn off strict mode and mysql won’t complain any more.

To make things clear: your database definition says «this field must have default value defined», and by doing steps from above you say to MySql «neah, just ignore it». So if you just want to do some quick fix locally this solution is ok. But generally you should investigate in your database definition and check if field really needs default value and if so set it. And if default value is not needed this requirement should be removed to have clean situation.

answered Aug 17, 2018 at 8:22

MilanG's user avatar

MilanGMilanG

6,9942 gold badges35 silver badges65 bronze badges

8

As others said, this is caused by the STRICT_TRANS_TABLES SQL mode.

To check whether STRICT_TRANS_TABLES mode is enabled:

SHOW VARIABLES LIKE 'sql_mode';

To disable strict mode:

SET GLOBAL sql_mode='';

answered Aug 24, 2018 at 12:35

Damjan Pavlica's user avatar

Damjan PavlicaDamjan Pavlica

31.5k10 gold badges71 silver badges76 bronze badges

3

Before every insert action I added below line and solved my issue,

SET SQL_MODE = '';

I’m not sure if this is the best solution,

SET SQL_MODE = ''; INSERT INTO  `mytable` (  `field1` ,  `field2`) VALUES ('value1',  'value2');

answered Mar 22, 2017 at 17:12

Vinith's user avatar

VinithVinith

1,26414 silver badges25 bronze badges

2

Modify your query and add «IGNORE» as:

INSERT IGNORE INTO  `mytable` (  `field1` ,  `field2`) VALUES ('value1',  'value2');

answered Feb 15, 2018 at 9:05

Rohit Dhiman's user avatar

3

Its work and tested Copy to Config File: /etc/mysql/my.cnf OR /bin/mysql/my.ini

[mysqld]
port = 3306
sql-mode=""

then restart MySQL

ddb's user avatar

ddb

2,4237 gold badges28 silver badges38 bronze badges

answered Aug 30, 2016 at 7:44

Devraj Gupta's user avatar

0

This appears to be caused by a long-standing (since 2004) bug (#6295) in MySQL, titled

Triggers are not processed for NOT NULL columns.

It was allegedly fixed in version 5.7.1 of MySQL (Changelog, last entry) in 2013, making MySQL behave as “per the SQL standard” (ibid).

answered Apr 24, 2015 at 17:52

B98's user avatar

B98B98

1,22912 silver badges20 bronze badges

3

For Windows WampServer users:

WAMP > MySQL > my.ini

search file for sql-mode=""

Uncomment it.

answered Apr 21, 2017 at 16:23

Andrew's user avatar

AndrewAndrew

18.8k13 gold badges104 silver badges118 bronze badges

1

In Windows Server edit my.ini (for example program files\mysql\mysql server n.n\my.ini)

I would not simply set the sql-mode=»», rather I suggest one removes STRICT_TRANS_TABLES from the line, leave everything as-was, and then restart MySQL from the services utility. Add a comment for future programmers who you are and what you did.

answered Dec 3, 2018 at 18:14

Bill Degnan's user avatar

2

Most of these answers are a lot of work for the not-seasoned coder. Like mentioned the issues is with STRICT_TRANS_TABLES.

First verify STRICT_TRANS_TABLES is running.

$ mysql -u root -p -e "SHOW VARIABLES LIKE 'sql_mode';"

You can disable strict mode on your MySQL server by running the following command on your Linode’s command line:

$ mysql -u root -p -e "SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';"

Then, you can verify that the mode is set by running the following:

$ mysql -u root -p -e "SELECT @@GLOBAL.sql_mode;"

This answer was found here https://www.linode.com/community/questions/17070/how-can-i-disable-mysql-strict-mode

answered Sep 30, 2022 at 21:24

themeowman 's user avatar

This is for SYNOLOGY device users:


  • How to set global variables (strict mode OFF) on SYNOLOGY device.
    (checked on DSM 7.0.1-42218 — device model DS418)

Used PUTTY to connect:
login as root and
sudo su after… (to be admin total)

  • if not exist create my.cnf in:

MariaDB 5:
/var/packages/MariaDB/etc
MariaDB 10:
/var/packages/MariaDB10/etc

  • this should be in the file (at least for strict mode off)
# custom configs
[mysqld]
innodb_strict_mode = OFF
sql_mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
  • restart mysqld daemon:
    MariaDB 5:
    /usr/syno/bin/synopkg restart MariaDB
    MariaDB 10:
    /usr/syno/bin/synopkg restart MariaDB10

  • check for strict mode enabled at these two global options — both should be not there or off (see config above)

  • log into mysql:
    mysql -u root -p

  • enter password:

show variables like ‘sql_mode’;
show variables like ‘%STRICT%’;


answered Jan 9, 2022 at 6:32

Peter Maly's user avatar

Peter MalyPeter Maly

411 silver badge7 bronze badges

i set the fields to not null and problem solved, it updates when an information is commanded to store in it, no more showing msqli message that the field was empty cus you didnt insert value to it, well application of this solution can work on some projects depends on your project structure.

answered Nov 25, 2016 at 1:34

ExploreTech's user avatar

1

i solved problem changing my.ini file located in data folder. for mysql 5.6 my.ini file moved to data folder rather the bin or mysql installation folder.

answered Jun 2, 2019 at 9:58

sadik keskin's user avatar

I think in name column have null values in this case.

update try set name='abc' where created_by='def';
  

answered Jun 25, 2020 at 5:56

Sasindu's user avatar

I am using Xampp 7.3.28-1 for Linux. It uses MariaDB 10.4.19. Its configuration file is:
/opt/lampp/etc/my.cnf

It does NOT contain an entry that defines sql_mode.
However the query «select @@GLOBAL.sql_mode;» does return a result and it contains the problematic STRICT_TRANS_TABLES. I guess it is by default now.

My solution was to explicitly define the mode by adding this line below [mysqld]:
sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

You can define the modes that you need or just leave it blank.

answered Jun 17, 2021 at 19:05

M.Paunov's user avatar

M.PaunovM.Paunov

1,7471 gold badge15 silver badges19 bronze badges

I found that once I removed what was a doubling up of a foreign key and primary key, when I could have just used the foreign key as the primary key alone in the table. All my code then worked and I was able to upload to db.

answered Nov 21, 2021 at 10:34

Spinstaz's user avatar

SpinstazSpinstaz

2876 silver badges12 bronze badges

in my case
Centos 8
Directadmin
Mariadb

Go to and edit:

- /etc/my.cnf

Add this text in last line — save file, and restart mysql

sql-mode=""

Final same as:

[mysqld]
...
sql-mode=""

Don’t forget

/bin/systemctl restart mysqld.service

answered Apr 19 at 17:37

Hoàng Vũ Tgtt's user avatar

ERROR 1364: 1364: Field 'ssl_cipher' doesn't have a default value .

SQL Statement:

INSERT INTO `samedaycrm4`.`users` (`Host`, `User`, `Password`) VALUES ('%', 'Bonnie', '*BB71B8925EED8E5387A872A38E566BFCB0F78071')

I am trying to determine the cause of the error ERROR 1364: 1364: Field ‘ssl_cipher’ doesn’t have a default value..?

Thanks in advance…

Charaf JRA's user avatar

Charaf JRA

8,2491 gold badge34 silver badges44 bronze badges

asked Aug 30, 2013 at 2:12

Eae's user avatar

//This happens due to the internal structure of user table in mysql database (mysql.user) has many column of administrative privileges which accept ‘N’ or ‘Y’ value but not NULL Value. Not assigning these values in user addition syntax by INSERT method will provide null values to table and hence error 1364 occur.
//instead using GRANT syntax will give no administrative privileges to user
mysql>use mysql;

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE
       -> ON database.*  //for all tables in DATABASE database
       -> TO 'user'@'localhost'
       -> IDENTIFIED BY 'password';

//user will get created

answered Oct 2, 2013 at 12:48

Uday Hiwarale's user avatar

Uday HiwaraleUday Hiwarale

4,0386 gold badges46 silver badges50 bronze badges

The ssl_cipher column in your table has been marked non-null, but your INSERT query isn’t providing a value for it. MySQL will try to assign the default value in these circumstances, but your column hasn’t been given one.

You need either to set a default value for ssl_cipher, or alter the table such that the ssl_cipher is not marked as non-null

answered Aug 30, 2013 at 2:15

4

FYI check comment from «Sergei Golubchik» at https://bugs.mysql.com/bug.php?id=14579

[ It doesn’t look like a bug to me.
INSERT INTO mysql.user is deprecated since 3.23 — one should use GRANT or CREATE USER to add new users.
As for the GRANT failing on Windows, it’s a duplicate of the BUG#13989, which is «Not a bug» either. GRANT fails because on Windows, installer adds the following line to my.ini
sql-mode=»STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION»
which prevents GRANT from auto-creating users.]

And finally the implementation for CREATE USER, you can find at —

https://dev.mysql.com/doc/refman/5.7/en/adding-users.html

It should solve your problem, using «CREATE USER» approach.

answered Aug 27, 2017 at 13:01

Sagar Mahewar's user avatar

1

Понравилась статья? Поделить с друзьями:
  • Ошибка 13637426 шкода рапид
  • Ошибка 1363 веста
  • Ошибка 13611 опель астра h z16xer
  • Ошибка 1361 хонда цивик
  • Ошибка 1361 хонда одиссей