Closed garethellis36 closed 7 years ago
CREATE TABLEversion( 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, createddatetime NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE
(
int(11) NOT NULL AUTO_INCREMENT,
int(11) DEFAULT NULL,
varchar(255) NOT NULL,
int(10) NOT NULL,
text,
datetime NOT NULL, PRIMARY KEY (
) ) 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.
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,
createddatetime 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:
We used the following migration:
Do we need to make the content field nullable?