Could not insert row with empty (not null) varchar column

[expired user #8023]'s profile image [expired user #8023] posted 8 years ago in General Permalink

Hello, it's not possible to create a new row with empty varchar columns.

  1. Create table:

create table test ( id int not null primary key auto_increment, col1 varchar(10) not null );

  1. Try to insert a row with col1 = '' (empty, but not null)

Thanks Andi

ansgar's profile image ansgar posted 8 years ago Permalink

Well, it is possible, but HeidiSQL expects you to insert something into at least one of the new fields, otherwise the new row is threwn away. Is that what you mean?

[expired user #8023]'s profile image [expired user #8023] posted 8 years ago Permalink

Not exactly. "At least on row" is not true. Heidi expects EVERY row (with not null no default) to be specified.

Try: create table test ( id int not null primary key auto_increment, col1 varchar(10) not null, col2 varchar(10) not null );

Create a new row with 'a' in col1.

Created statement: INSERT INTO test (col1) VALUES ('a');

Errormessage: SQL Fehler (1364): Field 'col2' doesn't have a default value

It's not possible to create the value '' for col2 because Heidi ignores empty rows. But they should not be ignored if null is not allowed;

[expired user #8023]'s profile image [expired user #8023] posted 8 years ago Permalink

Not exactly. "At least on row" is not true. Heidi expects EVERY row (with not null no default) to be specified.

Sorry: i mean col instead of row: Not exactly. "At least one of the fields" is not true. Heidi expects EVERY col (with not null no default) to be specified.

[expired user #8023]'s profile image [expired user #8023] posted 8 years ago Permalink

Please fix this. It should be possible to insert a new row with an empty (not null) field. If a column has no default value it can not be omitted when creating the insert statement.

Please login to leave a reply, or register at first.