Symfony2: doctrine:mapping:import throws Doctrine\

2019-08-10 21:00发布

I want to import a Doctrine mapping for a table called stores. I do:

./app/console doctrine:mapping:import MyBundle annotation --filter="stores" 

I get the error:

[Doctrine\ORM\Mapping\MappingException]                                                                              
  Table Cat_map has no primary key. Doctrine does not support reverse engineering from tables that don't have a prima  
  ry key. 

Am I using the filter incorrectly? I dont want doctrine to try and map any table other than 'stores'

Requested create syntax:

CREATE TABLE `stores` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `storeid` int(11) NOT NULL,
  `store` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=96 DEFAULT CHARSET=utf8;

3条回答
The star\"
2楼-- · 2019-08-10 21:39

Despite the --filter attribute Doctrine analyse all the tables. If everything is OK then it go through the filter creating only the specified entity.

So, you should try to fix the cat_map table adding a primary key. If you're not figuring out a way or if you got particular needs, please update your question including the cat_map part.

I hope this helps!

查看更多
Rolldiameter
3楼-- · 2019-08-10 21:39

Use something other than doctrine for existing databases. Doctrine hasn't fixed this issue for many years.

查看更多
SAY GOODBYE
4楼-- · 2019-08-10 21:45

You can tell Doctrine to ignore tables that match a certain regex. For example, if you want to ignore tables that begin with "custom_", put this in your config.yml:

doctrine:
    dbal:
        schema_filter: /^(?!custom_)/

This seems to do the trick. For for information: http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html#manual-tables

查看更多
登录 后发表回答