错误:“索引”表中不存在”尝试在 Doctrine 2.0 CLI 中创建实体时
我有一个 mySQL 数据库。我正在尝试让 Doctrine2 从 MySQL 模式创建实体。我在我们的生产数据库中尝试了此操作,并收到以下错误:
[Doctrine\DBAL\Schema\SchemaException] 表用户上不存在索引 ''
然后我创建了一个简单的测试数据库,只有一个表,只有三个字段:一个自动增量主键字段和三个 varchar 字段。当尝试让学说从该数据库创建实体时,我遇到了同样的错误。
这是我试图为其创建实体的表。 (应该很简单)
mysql> desc user;
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| iduser | int(11) | NO | PRI | NULL | auto_increment |
| firstname | varchar(45) | YES | | NULL | |
| lastname | varchar(45) | YES | | NULL | |
| username | varchar(45) | YES | | NULL | |
+-----------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
这是我尝试创建所述实体时使用的命令:
./doctrine orm:convert-mapping --from-database test ../models/test
我正在运行:
- 5.1.49-1ubuntu8.1 (Ubuntu)
- mysql Ver 14.14 Distrib 5.1.49,for debian-linux-gnu (i686) 使用 readline 6.1
- Doctrine 2.0.1
I have a mySQL database. I am trying to get Doctrine2 to create entities from the MySQL schema. I tried this with our production database, and got the following error:
[Doctrine\DBAL\Schema\SchemaException] Index '' does not exist on table user
I then created a simple test database with only one table, and only three fields: an auto-increment primary key field and three varchar fields. When attempting to have doctrine create entities from this database, I got the same error.
Here is the table that I was trying to create an entitie for. (Should have been simple)
mysql> desc user;
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| iduser | int(11) | NO | PRI | NULL | auto_increment |
| firstname | varchar(45) | YES | | NULL | |
| lastname | varchar(45) | YES | | NULL | |
| username | varchar(45) | YES | | NULL | |
+-----------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
Here is the command that I used in an attempt to get said entities created:
./doctrine orm:convert-mapping --from-database test ../models/test
I am running:
- 5.1.49-1ubuntu8.1 (Ubuntu)
- mysql Ver 14.14 Distrib 5.1.49, for debian-linux-gnu (i686) using readline 6.1
- Doctrine 2.0.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在面临着同样的问题。我已将问题追溯到未正确识别/设置主键。默认值为 boolean(false),它被转换为字符串 ''。 Doctrine 随后无法找到该属性的索引。 ;-)
解决方案:定义一个主键。
I am facing the same problem right now. I have traced the problem back to the primary key being not identified / set correctly. The default value is boolean(false) which is cast to the string ''. Doctrine subsequently fails to locate an index for this attribute. ;-)
Solution: Define a PRIMARY KEY.