尝试SQL错误时测试的Symfony 2应用程序 - 列已经存在,缺少表 [英] SQL errors when attempting to test Symfony 2 app - columns already exist, tables missing
问题描述
我在下面的测试设置中所述 和也在这里。当我尝试运行我的测试,测试数据库在创建的过程中,我得到了以下错误:
I'm following the test setup described here and also here. When I attempt to run my tests, and the test db is in the process of being created, I get the following errors:
[学说\\ ORM \\工具\\ ToolsException]结果
架构工具失败,错误CREATE INDEX ON deletedAtidx SurveyHash(deletedAt)''在执行时出现异常:结果
SQLSTATE [HY000]:常规错误:1索引deletedAtidx已经存在,而执行DDL:CREATE INDEX ON deletedAtidx SurveyHash(deletedAt)
[Doctrine\ORM\Tools\ToolsException]
Schema-Tool failed with Error 'An exception occurred while executing 'CREATE INDEX deletedAtidx ON SurveyHash (deletedAt)':
SQLSTATE[HY000]: General error: 1 index deletedAtidx already exists' while executing DDL: CREATE INDEX deletedAtidx ON SurveyHash (deletedAt)
[主义\\ DBAL \\异常\\ TableExistsException]结果
在执行'CREATE INDEX ON deletedAtidx SurveyHash(deletedAt)发生异常:结果
SQLSTATE [HY000]:常规错误:1索引deletedAtidx已经存在
[Doctrine\DBAL\Exception\TableExistsException]
An exception occurred while executing 'CREATE INDEX deletedAtidx ON SurveyHash (deletedAt)':
SQLSTATE[HY000]: General error: 1 index deletedAtidx already exists
[主义\\ DBAL \\驱动程序\\ PDOException]结果
SQLSTATE [HY000]:常规错误:1索引deletedAtidx已经存在
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000]: General error: 1 index deletedAtidx already exists
[PDOException]结果
SQLSTATE [HY000]:常规错误:1索引deletedAtidx已经存在
[PDOException]
SQLSTATE[HY000]: General error: 1 index deletedAtidx already exists
学说:模式:创建[--dump-SQL] [--em [=...]]
doctrine:schema:create [--dump-sql] [--em[="..."]]
清除数据库
[主义\\ DBAL \\ DBALException]结果
在执行DELETE FROM PageImage发生异常:结果
SQLSTATE [HY000]:常规错误:1没有这样的表:PageImage
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'DELETE FROM PageImage':
SQLSTATE[HY000]: General error: 1 no such table: PageImage
[PDOException]结果
SQLSTATE [HY000]:常规错误:1没有这样的表:PageImage
[PDOException]
SQLSTATE[HY000]: General error: 1 no such table: PageImage
学说:夹具:负载[--fixtures [=...] [--append] [--em =...] [--purge-与截形]
doctrine:fixtures:load [--fixtures[="..."]] [--append] [--em="..."] [--purge-with-truncate]
主义\\ DBAL \\异常\\ TableNotFoundException:执行选择t0.label AS label_1,t0.value AS从_2 T0设置WHERE t0.label =发生异常? LIMIT 1使用参数[Web服务]:
Doctrine\DBAL\Exception\TableNotFoundException : An exception occurred while executing 'SELECT t0.label AS label_1, t0.value AS value_2 FROM Setting t0 WHERE t0.label = ? LIMIT 1' with params ["webservice"]:
SQLSTATE [HY000]:常规错误:1没有这样的表:设置
SQLSTATE[HY000]: General error: 1 no such table: Setting
看着我的实体,在 deletedAt
指数的不的在我的 SurveyHash
实体,并且我有两个实体 PageImage
和设置
,但没有被创建的那些表,作为验证通过sqliteman。进一步的测试(请参阅下面的答案之一,评论)显示,它使用相同的索引名称抛出一个错误,由于多个表。
Looking at my entities, the deletedAt
index is not declared twice in my SurveyHash
entity, and I have entities for both PageImage
and Setting
, yet those tables aren't being created, as verified by sqliteman. Futher testing (see the comments in one of the answers below) show that it's throwing an error due to multiple tables using the same index name.
我的 config_test.yml
有以下几点:
doctrine:
dbal:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.db
charset: UTF8
orm:
auto_generate_proxy_classes: true
auto_mapping: true
我有点有限在数据库中的信息,我可以由于NDA分享,所以我希望这些错误是在上面的链接或我的 config_test.yml 什么结果code>。我使用的Symfony 2.4.6,如果有差别。
I'm a bit limited in the database info I can share due to a NDA, so I'm hoping these errors are a result of something in the links above or my config_test.yml
. I'm using Symfony 2.4.6, if that makes a difference.
推荐答案
我认为你正在试图做一个学说:模式:更新
表上,其中的数据集有外键或者你想添加多个数据集。
I think that you're trying to do a doctrine:schema:update
on tables where the datasets have foreign keys or you're trying to add multiple datasets.
什么你可以尝试是如此删除数据库架构,重新创建它,然后用数据填充它。
What you could try is so to drop the database schema, recreate it and then refill it with the data.
因此,首先做一个 PHP应用程序/控制台学说:架构:降--force
,那么 PHP应用程序/控制台学说:模式:创建
然后学说:灯具:负载
So first do a php app/console doctrine:schema:drop --force
, then php app/console doctrine:schema:create
and then doctrine:fixtures:load
.
我有同样的问题,这对我的作品。
I had the same issues and this works for me.
我刚刚飞过的第一个链接,你在做什么是调用学说:模式:创建
多次,这当然不会因为你的工作已经已经创建它们。你只可以学说:架构:更新--force
它们或下降重建/创造!
I just flown over the first link and what you're doing is to call doctrine:schema:create
multiple times, which of course won't work because you've already created them. You only could doctrine:schema:update --force
them or recreate with drop/create!
答案
据低于此评论回答错误是,他给了不同的表目前存在的指标相同的名称,但是从指数名称必须是独一无二的!
According to the comments below this Answer the Error was that he gave differnet indexes on different tables the same name, but the names from index MUST be unique!
这篇关于尝试SQL错误时测试的Symfony 2应用程序 - 列已经存在,缺少表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!