3

we use Symfony 2 the first time and my company uses an existing MySQL database. Is there a possibility to "import" it in doctrine or can we just use this database and create php/doctrine entities after our existing tables?

If you have some good stuff to read about this topic just post it. Thanks, Pete

Pete
  • 564
  • 4
  • 29
  • i wouldn't even go there. i think it's best to generate the entities and the database and then create a little php script that imports the data through entities (and not directly to the database). from my experience with doctrine i'd assume it's the best method and most likely to work smoothly – galchen Dec 18 '12 at 10:38
  • http://stackoverflow.com/a/10614792/1259367 just don't add the filter if you want to import everything :) – Snroki Dec 18 '12 at 11:20
  • 1
    After searching for a while i found this: [link](http://symfony.com/doc/2.0/cookbook/doctrine/reverse_engineering.html) – Pete Dec 18 '12 at 11:23

1 Answers1

2

It's obviously better to create database from entities definition, than create enities from existing database. This is a main drawback of Doctrine2...

But it's possible and not so complicated if you have a "sane" existing model. Here is some stuff from my TODO list for model reverse engineering :

  • Use "id" named auto_increment integer as ID of each table,
  • Use SQL TINYINT only for boolean mapped fields ! Use SMALLINT if you need a short int.
  • Using foreign keys as composite key is only permitted from Doctrine 2.1
AlterPHP
  • 12,667
  • 5
  • 49
  • 54