I have two separated Symfony projects working with one database. The first project is on Symfony 3.2 and the second is on Symfony 2.8. Database is MySQL. All is in production stage and all is working fine.
Now I have some Entity classes in the first project and don't have them in the second one. We haven't needed the entities in the second project before but now I need to work with them in the second project.
I copied the entities from the first project to the second. We use annotations.
After this I checked my database and executed the command on the second project: app/console doctrine:schema:update --force And got the error: Base table or view already exists: 1050 Table 'crm_user' already exists. If I execute the command with --dump-sql option (app/console doctrine:schema:update --dump-sql) I see creation the table that already exists!
CREATE TABLE crm_user (id INT AUTO_INCREMENT NOT NULL, ...
So the doctrine schema update doesn't see that the DB table has been already created. How to fix it? I tried to clear all cache (cache:clear), doctrine metadata cache (doctrine:cache:clear-metadata), query cache (doctrine:cache:clear-query) and no success. I got the same error after this. If I try to validate doctrine schema there will not be the new table. And of course I cannot drop tables data because all is in production stage.
May be someone faced problems like this. I appreciate any suggestions.
I highly recommend not messing like this with two different projects and a single DB. If you need so, then simply let one be the Doctrine "master" where you do the modifications, and only there run the schema:update. Better than that, and way more elegant, would be to create a vendor that you can import with composer and it's your Doctrine entities vendor. This will then manage all the DB / Repositories and you can re-use it for many different projects having the code only in one place.
That will solve this and fix what you are not doing right in my point of view: Having duplicate entities pointing to the same DB structure, which will be always be a pain to maintain, and it does not deal well with the KISS principle and code duplication.