Tuesday, December 30, 2014

Re: 1.3 Migration Question re:NULL and Defaults

Can I assume that you are working on a copy of the original database?

If so, please verify that a default value is specified for that column. Kindly provide us with the definition of it.

It is quite alright for CakePHP to provide a NULL for the column on an insert, MySql should then set the value to the default one.

Enjoy, John

On Tuesday, 30 December 2014 20:18:03 UTC+2, MikeK wrote:
I am porting a 1.2.0.5875 app to 1.3 in preparation for moving to 2.X. I have several fields (tax, amount, fee) in an order record all with NULL set to "No", each is a decimal(6,2) field, and each has default value of 0.00

The following code worked fine and dandy in the 1.2 system and in the event nothing was specified by the user for tax, amount, or fee, they were properly set to 0.00 in the DB:

$this->cleanUpFields(); //WILL REMOVE AS THIS IS DEPRECATED
$this->Order->create();
if ($this->Order->save($this->data)) {

In my 1.3 migration build I am getting 'tax' cannot be NULL and I see in the SQL insert op that indeed it is being set to NULL, and thus MySQL chokes on it.

Why did it operate correctly in the old 1.2 system and what should I do to correct this? It is pervasive across numerous classes and I want to get it right the first time.

Is this perhaps a difference in the way the form helper is handling initialization of the fields? Or somewhere in the model? I did not need to specify validation for these fields as used back in 1.2 etc.

Thanks in advance!

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: