Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

load task not using Entity table name #18

Closed
Sgoettschkes opened this Issue Oct 31, 2011 · 7 comments

Comments

Projects
None yet
6 participants

I got a entity named "order" within my application and cannot use doctrine:fixtures:load as it tries to DELETE FROM order which breaks MySQL. I got the following annotation within the entity, but it doesn't change anything:
@ORM\Table(name="Order")

As a quickfix, I added line 119 in Doctrine\Common\DataFixtures\Purger\ORMPurger:
$tbl = '' . $tbl . '';

It works for me now, but I guess that's not a clean solution.

Same issue here with :

  • @ORM\Table(name="group")

Order and Group are reserved words in MySQL.

You may be able to get by with @orm\Table(name="Order'")` (notice the backticks inside the quotes), but that may not work.

You're best off changing the table name to something that doesn't conflict. (orders, customer_order, appname_order, etc). You can still call the entity "Order" or "group" but change the table name(s)

mbadolato, as said, the entity got the annotation @orm\Table(name="order") already, but it is not used by the fixtures bundle.

Your annotation is telling Doctrine to name your table "Order" which is a reserved word in MySQL. Try changing that and see if that fixes your issue. Your fixture load is essentially doing "INSERT INTO order [...]" which mysql would interpret as bad SQL.

mysql> INSERT INTO order (id, foo) VALUES (NULL, 'bar');
ERROR 1064 (42000): 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 'order (id, foo) VALUES (NULL, 'bar')' at line 1

You'll need to change the name of the table, as stated above. Again, you can try putting back tics around Order inside the quotes, but it may not work in this situation, plus Doctrine doesn't really recommend that anyway. But you can still do

/**
 * @ORM\Entity
 * @ORM\Table(name="prefix_order")
 */
class Order
{
    // ...
}

And that will be fine

Member

stof commented Nov 5, 2011

@mbadolato the backtcks were present in the comment of @Sgoettschkes but they are parsed by github as they have a meaning in Markdown. I just editted his comment to use a Markdown code syntax arroung the annotation to avoid this issue.

the clean solution is indeed to avoid using a reserved keyword but this is still a bug in Doctrine DataFixtures as it removes the explicit escaping. However, this is not the good issue tracker as the purger is part of the data-fixtures library, not of the bundle itself. Please report it on the Doctrine project.

@kinncj kinncj referenced this issue in doctrine/dbal Jun 10, 2013

Closed

Escaped table name #333

Owner

beberlei commented Jun 18, 2013

Not quoting in DELETE was fixed a while ago.

@beberlei beberlei closed this Jun 18, 2013

titenis commented Jun 5, 2017

I am still able to replicate this, though. The entity is named 'Order' and purging of database is not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment