Field 'xxxx' doesn't have a default value

Alles, was MariaDB und MySQL betrifft, kann hier besprochen werden.

Field 'xxxx' doesn't have a default value

Postby musicweb » 10. May 2021 13:14

We are running mariadb version 10.3.27
When trying to insert a record we get the error:
Field 'xxxx' doesn't have a default value

Our admin has to go in and change the sql mode to:
NO_ENGINE_SUBSTITUTION
and the errors go away...

A few weeks, or a month go by and the errors start again.
So our admin has to change the sql mode again...

Trying to change this field to have a default value,
id int(11) not null default none primary auto_increment

This is one of the fields giving us the error, but we can't give it a default value.
We tried this query, but it doesn't work:
alter table `customer` modify `customer_id` int(11) DEFAULT null;
musicweb
 
Posts: 2
Joined: 10. May 2021 13:12
XAMPP version: 7.4.12
Operating System: Debian Linux 10

Re: Field 'xxxx' doesn't have a default value

Postby JJ_Tagy » 10. May 2021 14:06

In your first example, you make it not null but don't want to provide a default value. That is a problem. Either your application must provide the value on insert or provide a valid default value if you omit it in your code. Is there some reason the default can't be 0?
JJ_Tagy
 
Posts: 788
Joined: 30. January 2012 13:44
XAMPP version: 5.5.15
Operating System: Windows 10 Pro x64

Re: Field 'xxxx' doesn't have a default value

Postby musicweb » 10. May 2021 14:21

I tried to set it to '0' through phpmyadmin and it said it was successfully changed,
but the change never took affect. Is it because it's primary and auto-increment?
musicweb
 
Posts: 2
Joined: 10. May 2021 13:12
XAMPP version: 7.4.12
Operating System: Debian Linux 10

Re: Field 'xxxx' doesn't have a default value

Postby JJ_Tagy » 10. May 2021 15:22

Oh, I didn't notice this was your primary for some reason.

Yes, you can't make a default as auto_increment will take care of it.

Perhaps your insert code has an issue?
JJ_Tagy
 
Posts: 788
Joined: 30. January 2012 13:44
XAMPP version: 5.5.15
Operating System: Windows 10 Pro x64

Re: Field 'xxxx' doesn't have a default value

Postby Altrea » 10. May 2021 15:56

That error does not make sense. If a field is primary key and auto increment it does not have to had a default value.

Are there any chances that we can reproduce your environment like providing a database dump?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to MariaDB - MySQL

Who is online

Users browsing this forum: No registered users and 10 guests