[DC-582] DataDict entry missing for datetime type for MySQL causes migrations to fail due to sql error Created: 18/Mar/10  Updated: 10/Jan/12  Resolved: 29/Mar/10

Status: Resolved
Project: Doctrine 1
Component/s: Migrations
Affects Version/s: 1.2.0, 1.2.1
Fix Version/s: None

Type: Bug Priority: Critical
Reporter: Rich Birch Assignee: Jonathan H. Wage
Resolution: Invalid Votes: 0
Labels: None
Environment:

LAMP



 Description   

I discovered this whilst trying out migrations via symfony. I added a datetime field to my schema.yml and generated the migrations, but upon running the migration I got the following error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '()' at line 1. Failing Query: "ALTER TABLE order_item ADD purchased_at datetime()"

The following code causes the failure in the actual migration:

$this->addColumn('order_item', 'purchased_at', 'datetime', '', array());

because it generates the following sql:

ALTER TABLE order_item ADD purchased_at datetime()

The diff from my patched version which fixes the issue is as follows:

Index: Doctrine/DataDict/Mysql.php
===================================================================
— Doctrine/DataDict/Mysql.php (revision 7415)
+++ Doctrine/DataDict/Mysql.php (working copy)
@@ -227,6 +227,7 @@
return 'DATE';
case 'time':
return 'TIME';
+ case 'datetime':
case 'timestamp':
return 'DATETIME';
case 'float':

It's against the following repository file:

http://doctrine.mirror.svn.symfony-project.com/branches/1.2/lib/Doctrine/DataDict/Mysql.php

I hope this is useful and gets committed



 Comments   
Comment by Rich Birch [ 22/Mar/10 ]

I've just discovered that the same issue exists for fields of type 'text':

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') NOT NULL, session_time DATETIME NOT NULL, INDEX session_id_index_idx (session_' at line 1. Failing Query: "CREATE TABLE session (id BIGINT AUTO_INCREMENT, session_id VARCHAR(64) NOT NULL, session_data text() NOT NULL, session_time DATETIME NOT NULL, INDEX session_id_index_idx (session_id), PRIMARY KEY(id)) ENGINE = INNODB"

from the following schema:

Session:
columns:
session_id:

{ type: string(64), notnull: true }

session_data:

{ type: text, notnull: true }

session_time:

{ type: timestamp, notnull: true }

indexes:
session_id_index:
fields: [ session_id ]
unique: true

I guess there may be other field entries missing too. Is there a comprehensive list of doctrine field types somewhere?

Comment by Rich Birch [ 22/Mar/10 ]

Ok, I might have been being dumb here. I've just checked the doctrine documentation for defining the schema (http://www.doctrine-project.org/documentation/manual/1_2/en/defining-models) and there's no mention of a datetime or text field (I've just realised that I should have used string instead of text anyway), but datetime still works as a column type so shouldn't it be documented?

I guess either datetime should be fully removed or fully supported

Comment by Jonathan H. Wage [ 29/Mar/10 ]

You should be using the Doctrine portable types. So you would use date or timestamp I believe and Doctrine will convert it to the appropriate type for your dbms.

Comment by Anatolie Marinescu [ 10/Jan/12 ]

not correctly generated migration, in my case generated:

$this->addColumn('tree', 'published_at', 'datetime', '', array(
));

but if change the fourth parameters on null, all ok

Generated at Sat Aug 23 01:34:00 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.