josegonzalez / cakephp-version

CakePHP3: plugin that facilitates versioned database entities

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Should "content" field be nullable?

garethellis36 opened this issue · comments

CREATE TABLE version(idint(11) NOT NULL AUTO_INCREMENT,version_idint(11) DEFAULT NULL,modelvarchar(255) NOT NULL,foreign_keyint(10) NOT NULL,fieldvarchar(255) NOT NULL,contenttext,created datetime NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

The NULLability of the 'content' field is not specified in this SQL. We are getting save failures for new entities with the following error:

Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'content' cannot be null

We used the following migration:

<?php

use Phinx\Migration\AbstractMigration;

class CreateVersions extends AbstractMigration
{
    public function change()
    {
        //set-up according to https://github.com/josegonzalez/cakephp-version
        $this->table('version')
             ->addColumn('version_id', 'integer', ['null' => true])
             ->addColumn('model', 'string')
             ->addColumn('foreign_key', 'integer')
             ->addColumn('field', 'string')
             ->addColumn('content', 'text')
             ->addColumn('created', 'datetime')
             ->addColumn('user_id', 'integer', ['null' => true])
             ->create();
    }
}

Do we need to make the content field nullable?

Yeah, if one of the fields in your model is nullable, then that content field will also need to be nullable.