I have a fresh Symfony 2.8 installation, with doctrine and MySQL 5.6 stack.
After executing a doctrine:schema:update --force
, i can see
Database schema updated successfully! "x" queries were executed
Here is my problem : Even if i execute it multiple time, doctrine always find schema differences.
With the --dump-sql
, i can see that all of these queries are related to :
- adding NOT NULL on string primary key
- adding NOT NULL on datetime field
However, when i check my database, these columns already have a NOT NULL.
Here is an example on a single property/column :
class MyEntity
{
/**
* @ORM\Id
* @ORM\Column(type="string", length=5, name="cd_key")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $code;
...
Here is the result of a SHOW CREATE TABLE my_entity;
:
CREATE TABLE `my_entity` (
`cd_key` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
`label` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`number` int(11) NOT NULL,
PRIMARY KEY (`cd_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;
And here the query doctrine try to execute with the doctrine:schema:update
command :
ALTER TABLE my_entity CHANGE cd_key cd_key VARCHAR(5) NOT NULL;
- I clean my Symfony cache between each command execution.
- I try to add
nullable=false
on @Column annotation (event if it's already defined as an @Id), but no effect. - a
doctrine:schema:validate
don't find any mapping problem (except sync of course) - I try to drop and recreate the full database, but no effet.
Any ideas ?
nullable=false
mean that it addsNOT NULL
as a part of that column? Changing it tonullable=true
would allow the value to be null. – Captious