无法使用Doctrine和Symfony2在MySQL中创建表 [英] Unable to create table in MySQL using Doctrine and Symfony2

查看:183
本文介绍了无法使用Doctrine和Symfony2在MySQL中创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySql与Symfony2和Doctrine ORM合作。



创建实体后,我无法创建表。它引发了一个例外。

  anu @ anu-bridge:/ var / www / Symfony $ php app / console doctrine:schema: update --force --dump-sql 

[Doctrine\DBAL\Schema\SchemaException]
名称为product的表已经存在。

doctrine:schema:update [--complete] [--dump-sql] [--force] [--em [=...]]

我试图删除它,但仍然会抛出错误。

  anu @ anu-bridge:/ var / www / Symfony $ php app / console doctrine:schema:drop --force 
删除数据库模式...

[Doctrine\DBAL\Schema\SchemaException]
名称为product的表已存在。

doctrine:schema:drop [--dump-sql] [--force] [--full-database] [--em [=...]]

[Doctrine\DBAL\Schema\SchemaException]
名称为product的表已存在。

数据库中没有表。清除所有缓存的symfony和doctrine,但仍然是错误抛出。



Symfony2版本是2.0.1。

解决方案

我也遇到过类似的问题。很可能你有两个实体在不同的Bundles里面命名为Category。例如:

  src / Acme / SomeBundle / Entity / Product.php 
src / Acme / OtherBundle / Entity /请注意其中一个文件并重试控制台命令。

$ b $($)

$ p $ b

I am working with Symfony2 and Doctrine ORM using MySql .

After creating an Entity, I am not able to create the table. It throws an exception.

anu@anu-bridge:/var/www/Symfony$ php app/console doctrine:schema:update --force --dump-sql

[Doctrine\DBAL\Schema\SchemaException]
The table with name 'product' already exists.  

doctrine:schema:update [--complete] [--dump-sql] [--force] [--em[="..."]]

I tried to drop it , but still it throws the error.

anu@anu-bridge:/var/www/Symfony$ php app/console doctrine:schema:drop --force
Dropping database schema...

[Doctrine\DBAL\Schema\SchemaException]         
The table with name 'product' already exists.  

doctrine:schema:drop [--dump-sql] [--force] [--full-database] [--em[="..."]]

[Doctrine\DBAL\Schema\SchemaException]         
The table with name 'product' already exists.

There is no tables in the database. Cleared all the cache for symfony and doctrine, but still the error is throwing.

Symfony2 version is 2.0.1 .

解决方案

I've had a similar problem. Most likely you have two entities named Category inside different Bundles. For instance:

src/Acme/SomeBundle/Entity/Product.php
src/Acme/OtherBundle/Entity/Product.php

Comment one of these files and retry the console command.

这篇关于无法使用Doctrine和Symfony2在MySQL中创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆