Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Field 'user_data' doesn't have a default value in CI 2.0.3

I used CI's user guide to create my session table.

CREATE TABLE IF NOT EXISTS  `sessions` (
    session_id varchar(40) DEFAULT '0' NOT NULL,
    ip_address varchar(16) DEFAULT '0' NOT NULL,
    user_agent varchar(120) NOT NULL,
    last_activity int(10) unsigned DEFAULT 0 NOT NULL,
    user_data text NOT NULL,
    PRIMARY KEY (session_id),
    KEY `last_activity_idx` (`last_activity`)
);

This error shows whenever I have $db['default']['stricton'] = TRUE in my database.php

Error Number: 1364

Field 'user_data' doesn't have a default value

INSERT INTO sessions (session_id, ip_address, user_agent, last_activity) VALUES ('2b92823888c4c5eb4b5b2ae25282ce9e', '192.168.1.4', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1', 1317346730)

Filename: libraries/Session.php

Line Number: 327

However, I want to enforce strict SQL.

like image 423
zgosalvez Avatar asked Sep 30 '11 01:09

zgosalvez


1 Answers

From the reference - BLOB and TEXT columns cannot have DEFAULT values.

The BLOB and TEXT Types

You should add user_data field in your INSERT statement.

like image 79
Devart Avatar answered Oct 10 '22 15:10

Devart