fuel / oil

Fuel PHP Framework - Fuel v1.x Oil command-line package
http://fuelphp.com/docs/packages/oil/intro.html
106 stars 67 forks source link

CRUD scaffolding does not work with strict mode MySQL server #150

Closed fatpat closed 11 years ago

fatpat commented 12 years ago

There's a bug with the scaffolding/crud generator. Everything seems to work well but when I try to insert a new value from the generated controller into the database I have the following error:

Fuel\Core\Database_Exception [ 1364 ]: Field 'created_at' doesn't have a default value [ INSERT INTO `notes` (`titre`, `description`) VALUES ('qsdfqsd', 'fqsdfqsdf') ]

here is the generated mysql table:

 mysql> desc notes;
 +-------------+--------------+------+-----+---------+----------------+
 | Field       | Type         | Null | Key | Default | Extra          |
 +-------------+--------------+------+-----+---------+----------------+
 | id          | int(11)      | NO   | PRI | NULL    | auto_increment |
 | titre       | varchar(255) | NO   |     | NULL    |                |
 | description | text         | NO   |     | NULL    |                |
 | created_at  | int(11)      | NO   |     | NULL    |                |
 | updated_at  | int(11)      | NO   |     | NULL    |                |
 +-------------+--------------+------+-----+---------+----------------+
 5 rows in set (0.01 sec)

The fields created_at and updated_at can't be NULL and don't have a default value. When fuelphp is inserting the new record, those 2 fields are not set. If the MySQL server is configured to use "strict mode", then it's impossible to insert a new record without setting those 2 fields.

I think there's a bug here ...

WanWizard commented 12 years ago

Are we talking Model_Crud or ORM models?

fatpat commented 12 years ago

I'm talking CRUD:

php oil generate scaffold/crud person name:string
WanWizard commented 12 years ago

Ok, thanks. I'll have a look.

Looks like more bugs, because on an INSERT, created_at MUST have a value. Otherwise it's existence is rather pointless...

WanWizard commented 11 years ago

Just looked at the Model_Crud code. On a save() it will always set the "updated_at" column, and on INSERT, it will also set the "created_at" column. According to the commit log, this was already added on 2012-01-11.

What version of FuelPHP were you using? And what code exactly generated that error?