There is an issue with using unique => true
in defining an attribute as a primary key when using MYSQL 5.7.*.
protected function defineAttributes()
{
return array(
'eid' => array(AttributeType::Number, 'unique' => true, 'column' => ColumnType::PK)
);
}
According to my setting this error should not occur. Here is the error.
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1171 All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead
Here is the SQL executed.
system.db.CDbCommand.execute(CREATE TABLE `craft_venti_events` (
`eid` int(11) NOT NULL AUTO_INCREMENT NULL,
`eventid` INT(10) NULL,
`startDate` datetime NULL,
`endDate` datetime NULL,
`allDay` INT(10) NULL,
`repeat` INT(10) NULL,
`rRule` VARCHAR(255) NULL,
`summary` VARCHAR(255) NULL,
`isrepeat` INT(10) NULL,
`locale` VARCHAR(255) NULL,
`dateCreated` datetime NOT NULL,
`dateUpdated` datetime NOT NULL,
`uid` CHAR(36) NOT NULL DEFAULT 0,
PRIMARY KEY (eid)
) ENGINE=InnoDb DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci)
AttributeType::Number
, does that help? – Brad Bell Sep 19 '16 at 23:03unique
is unnecessary here as primary keys are unique by definition. What happens if you remove it? – Brad Bell Sep 19 '16 at 23:23