I'm developing my first ever application with PostgreSQL.
The Scenario
This is what my table "person" looks like:
Column | Type | Modifiers
------------+-----------------------------+-----------------------------------------------------
id | bigint | not null default nextval('person_id_seq'::regclass)
first_name | character varying(255) | not null
last_name | character varying(255) | not null
email | character varying(255) | not null
password | character varying(255) | not null
created_at | timestamp without time zone |
updated_at | timestamp without time zone |
Indexes:
"person_pkey" PRIMARY KEY, btree (id)
"person_email_unique" UNIQUE CONSTRAINT, btree (email)
"person_id_unique" UNIQUE CONSTRAINT, btree (id)
Referenced by:
TABLE "access" CONSTRAINT "access_person_id_foreign" FOREIGN KEY (person_id) REFERENCES person(id)
This was created using migrations in knex.schema.
If I run the following query in psql...
insert into person (first_name, last_name, email, password) values ('Max', 'Mustermann', '', '123123123');
I get back INSERT 0 1 and the row is successfully inserted:
id | first_name | last_name | email | password | created_at | updated_at
----+------------+------------+-----------------------------------+----------------+-------------------------+-------------------------
12 | Max | Mustermann | | 123123123 | |
My Question:
I expect the operation to fail, because no e-mail (NOT NULL) was specified. Why does it not fail?
Thank you very much for your help!
Max
nulland''are not the same thing. If you excluded email from your insert completely it would throw an errorNULL(except in Oracle).check(email <> '')orcheck(length(email) > 0).