Importing tables from external database in Symfony2 with doctrine

前端 未结 8 877
醉酒成梦
醉酒成梦 2020-12-12 18:18

I have a Symfony2 project with its own database, and now I want to connect to another database (another project) so I can modify some tables.

I created the new conne

相关标签:
8条回答
  • 2020-12-12 19:13

    You have to update the getTablePrimaryKeys function to:

    private function getTablePrimaryKeys(Table $table)
    {
        try {       
            $primaryKeyColumns = ($this->tables[$table->getName()]->hasPrimaryKey())?$this->tables[$table->getName()]->getPrimaryKey()->getColumns():array();
        } catch(SchemaException $e) {
            $primaryKeyColumns = array();
        }
    
        return array();
    }
    
    0 讨论(0)
  • 2020-12-12 19:14

    Note that --filter in your command should be populated with the Entity Class name and not the Table name. If the entity does not yet exists, the Entity Class name must compliment your table name. So if your table is user_table, the filter value would be UserTable.

    And then to work around that your DB has some tables that Doctrine cannot handle, you should whitelist the tables you do want allow Doctrine to manage. You can do this in your config file like, so:

    doctrine:
        dbal:
            # ... 
            schema_filter: /^(users_table|emails)$/
    

    alternatively you can specify this in your cli-config.php file.

    /** @var Doctrine\ORM\Configuration $config */
    $config->setFilterSchemaAssetsExpression('/^(users_table|email)$/');
    
    0 讨论(0)
提交回复
热议问题