Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maan's avatar
Level 1

string delimiters missing in insert query

Hallo, I've installed laravel 5.5, php7.0.23, mysql5.5.53 and a first application with auth. When I try to register a user there is this error:

(2/2) QueryException SQLSTATE[HY000]: General error: 1364 Field 'first_name' doesn't have a default value (SQL: insert into sos_users (name, email, password, updated_at, created_at) values (alonso, [email protected], $2y$10$XPCBYlJApea7xZ3TO5fFHuxwksRHcrtl0UjmoN0ZiP6//boIcQgr6, 2017-09-08 15:34:08, 2017-09-08 15:34:08)) in Connection.php (line 647)

at Connection->runQueryCallback('insert into sos_users (name, email, password, updated_at, created_at) values (?, ?, ?, ?, ?)', array('alonso', '[email protected]', '$2y$10$XPCBYlJApea7xZ3TO5fFHuxwksRHcrtl0UjmoN0ZiP6//boIcQgr6', '2017-09-08 15:34:08', '2017-09-08 15:34:08'), object(Closure)) in Connection.php (line 607)

The first query hav'nt the string delimiters '. Why? Thanks

0 likes
6 replies
Snapey's avatar

Your strings look fine.

The problem is that you have defined a first_name column in the database but you do not pass a first_name in the create.

It looks like the column is not nullable so you must provide either a value or tell the database a default to use

maan's avatar
Level 1

ok, define fields as nullable

robman70's avatar

Hi, I have a similar problem:

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (test_db.documents_rows, CONSTRAINT fk_dro_vat FOREIGN KEY (vat_type_id) REFERENCES vat_types (id`) ON DELETE NO ACTION ON UPDATE NO ACTION)

insert into `documents_rows` (`document_id`, `product_id`, `product_name`, `vat_type_id`, `created_by`, `updated_at`, `created_at`) 
values (4, 1, prodotto 1, 1, 1, 2022-07-18 18:33:24, 2022-07-18 18:33:24)

1 - It's not a problem with the foreign key: if I add the missing delimiters, the query works fine:

insert into `documents_rows` (`document_id`, `product_id`, `product_name`, `vat_type_id`, `created_by`, `updated_at`, `created_at`) 
values (4, 1, 'prodotto 1', 1, 1, '2022-07-18 18:33:24', '2022-07-18 18:33:24')

2 - Fields product_name, updated_at, created_at are defined as string in the corresponding model

I'm stuck. :-(

Tray2's avatar

@robman70 This is a completely other issue. Please open your own thread instead of reopening a four year old one.

Please or to participate in this conversation.