Welcome Guest, Not a member yet? Register   Sign In
Database Error loading my ci_session
#1

[eluser]Unknown[/eluser]
hi there I'm new at CI I was in the middle of a tutorial how to create a log in form when I stumbled into this error:



A Database Error Occurred

Error Number: 1364

Field 'user_data' doesn't have a default value

INSERT INTO `ci_sessions` (`session_id`, `ip_address`, `user_agent`, `last_activity`) VALUES ('516751bf8b43c5e9be41ff1751350a64', '127.0.0.1', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv', 1279172903)



can any one help me, you see I'm a newbie and only have a basic skills in php any help would be greatly appreciated, thanks
#2

[eluser]BrianL[/eluser]
WHen you get strange MySQL errors use MySQL forums... every possible error has hundreds of posts

At first glance error is simple; you haven't defined user_data column to have default value of NULL and in your query there is no value for user_data. Solution is to either change column or change query to set user_data to ''.

I suggest downloading MySQL Workbench.
#3

[eluser]InsiteFX[/eluser]
Code:
--
-- Table structure for CodeIgniter ci_sessions.
--
DROP TABLE IF EXISTS `ci_sessions`;

CREATE TABLE IF NOT EXISTS `ci_sessions` (
  `session_id` varchar(40) DEFAULT '0' NOT NULL,
  `ip_address` varchar(16) DEFAULT '0' NOT NULL,
  `user_agent` varchar(50) NOT NULL,
  `last_activity` int(10) unsigned DEFAULT 0 NOT NULL,
  `user_data` text NOT NULL,
  PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

InsiteFX
#4

[eluser]Derek Allard[/eluser]
InsiteFX has it right. You are saving sessions to a db without having created a table for it. Take another look at "Saving Session Data to a Database" in http://ellislab.com/codeigniter/user-gui...sions.html
#5

[eluser]WanWizard[/eluser]
Nope.

That would generate a table not found message. In this case, the user_data is defined like in InsiteFX's example (NOT NULL), but the INSERT from create_sess() doesn't include the user_data field, so it tries to insert a NULL value, which is not allowed.

So, either remove the 'NOT NULL' from your field definition, or add a "DEFAULT ""' to make sure it always has a value.

EDIT:

Which means that the example in the user_guide is wrong.
#6

[eluser]Derek Allard[/eluser]
Oh snap! Right you are. Updating userguide example for strict mode db.
#7

[eluser]theshiftexchange[/eluser]
[quote author="Derek Allard" date="1279302677"]Oh snap! Right you are. Updating userguide example for strict mode db.[/quote]

FYI the userguide is still wrong - it either needs a default value for 'userdata' - or allow for NULL.
#8

[eluser]Derek Allard[/eluser]
I fixed it here, so when CI2 goes out it'll be a part of that.




Theme © iAndrew 2016 - Forum software by © MyBB