0

I'm in the middle of a project development, and I'm frustrated with this problem.

Im running XAMPP under Ubuntu 10.04 (Lucid Lynx)
mySQL version : Ver 14.14 Distribution 5.1.41

The problem is that, mySQL is accepting null values even if the field is declared with
the NOT NULL constraint.

Example:

CREATE TABLE `STUDENT` (
  name VARCHAR(255) NOT NULL,
  age  INT
);


INSERT INTO `STUDENT` (age) VALUES (19);

In the query above. mySQL still accepts the data, even if I do not indicate any value for
the name column. Is there something wrong? Do I need to configure something in mySQL?

I really need help!

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by macobex
0

In my version of MySQL (5.1.34-community) your code produces the desired error:

Field 'name' doesn't have a default value

So after your INSERT there is really a new row in your table? Or do you just suppress the error messsages?

0

And I forgot to ask:
What value does name have after the insert? Is it NULL or an empty string? Could it be that somewhere in your configuration the emtpty string is set as a default?

0

Thank you for your concern sir. This problem is now solved.
I discovered that sql-mode must be set to STRICT_ALL_TABLES in order to produce the
desired error, rather than produce warnings only.

Anyway. Thank you again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.