php – How can I edit the sql commands of symfony doctrine when updating a schema?-ThrowExceptions

Exception or error:

I have the following error when I’m trying to update my database schema :

SQLSTATE[HY000]: General error: 1833 Cannot change column 'IdEcole': used in a foreign key constraint 'appartient_ibfk_2' of table 'tuteure.appartient' 

However, I don’t have anything that make the IdEcole AUTO_INCREMENT (in database or in my Entitites, only in the migrations.

When I execute the following line php bin/console doctrine:schema:update --dump-sql I have the following response :

ALTER TABLE Ecole CHANGE IdEcole IdEcole INT AUTO_INCREMENT NOT NULL;

So how can I edit this line to delete it ? Where is this line stored and where it comes from ?

How to solve:

Finally find where the problem cames from :

Symfony’s Doctrine use migrations to update your code and your database.
So, in my last migration file (in src/Migrations a file with a name like VersionNUMBER.php).

I edit this file which contains two method : up and down and I just delete the line :

ALTER TABLE Ecole CHANGE IdEcole IdEcole INT AUTO_INCREMENT NOT NULL;

And make a simple :

php bin/console doctrine:migrations:execute NUMBERVERSION

Where NUMBERVERSION is my number (the name of the migration file and the class)

And after :

php bin/console doctrine:schema:update

Leave a Reply

Your email address will not be published. Required fields are marked *