Entity framework migration "Table does not exist" - mysql

im new to entity framework , i created my entities from reverse engineering from a Mysql database that i have created in mysqlworkbench , and then i added some foreign keys in my entities and then i added a migration and tried to update my database but an error occured and it indicates that: "Table 'pidev.pidev.personal' doesn't exist".
"pidev" is the name of my database. personal is a super class for two other subclasses "candiadte" and "employee" and im using TPH as inheritance strategy.
PLZ i need some help.

thank you all for your replies , I SOLVED the problem in the UP() and DOWN()method in the migration file i removed the name of the database in each line like this "DropPrimaryKey("pidev.personal");" ==> DropPrimaryKey("personal");

Related

Symfony - migrations error: table with name "database.table" already exists

I have the following problem in my current Symfony 6 project. I have a Many to Many Relationship between two tables in my Database. Therefore a third table for the references got created.
Afterwards, I created an Entity for this thie reference table which I needed for a query. However, if I now want to create a new migration with the command php bin/console make:migration.
I always get the error "table with name "database.table" already exists"
I think the problem occurs because, obviously the table for this entity already exists and the migration command wants to create it. But how do I solve this issue?
Thanks for any ideas in advance. :)
Maybe you are trying to build ManyToMany with extra fields?
Then this is not a simple ManyToMany anymore: it's now a OneToMany + the inverse side of the ManyToOne relationship.
More details is here https://symfonycasts.com/screencast/collections/many-to-many-extra-fields

Error: ER_NO_SUCH_TABLE: how to synchronize the missing table after updating DB

i created a database having one table of Patient, i did my functions of get and post on rest api
when i wanted to add a new table of Doctors i had this error mn my CMD
So any one has an idea about how to update the database with synchronization of those files
thank you in advance
You can try:
Deleting existing migrations
Add migration
Update database

how to fix `MySql.Data.MySqlClient.MySqlException: 'Unknown column 'Key' in 'field list''` error in asp.net core and mysql hangfire problem?

i have create a cron job with asp.net core and mysql and hangfire, but when i run my project that got me an error like this the customset table doesn't exists so i have created a table called customset and rerun the project but that got me again an error like this MySql.Data.MySqlClient.MySqlException: 'Unknown column 'Key' in 'field list'. can anyone help me?
Generally, that error means that your entity class and the database table are out of sync. Based on the entity class, the provider is trying to select a column that doesn't actually exist on the corresponding table in the database, which means you've likely added a property to the class and didn't do a migration to propagate that change to the database.
Long and short, you need to add a migration and update your database, or if you're going with a database-first approach, fix your database so that it matches your entity class or just rerun the scaffolding.

Code first strange table exists error

I use code first convention and mysql database in asp.net application. First I created a data model. Second I created database using add-migration and update database. I see in MySQLWorkbench that my database was created.
After that I run my app to see how database work. Before one of views is created I 'ask' database for a list of users. The problem is that during linq query to get list of users there is thrown an exception. Message is Table 'Events' already exists. I do not understand this error. Yes, all tables in the database exits. There is not direct relation between these to tables.
I have stared looking for the answer in the Internet. I found only one solution. I droped database, deleted all migrations, created new migration and update-database, but the this solutions does not solve the problem.
Any ideas?
This problem have number 1050 in MySQL.
In my Seed method I can insert objects into database, and it works. But during app is running the exception is thrown. I try:
DROP TABLE IF EXISTS Events;
REPAIR TABLE Events;
I execute this queries in MySQLWorkbench and restart the application. Then I have "new" exception that: "Table 'Documents' already exists". When I try
DROP TABLE IF EXISTS Documents;
REPAIR TABLE Documents;
MySQLWorkbench: Error Code: 1217. Cannot delete or update a parent row: a foreign key constraint fails. So the problem still exists. Now I have exception "Table 'Documents' already exists". I check my Up method in migration class the first table which is created is Events, the second Documents. So I think that I should repair all tables, becouse in database-update command must create wrong database. But why it earlier works(?) I still do not know.

Symfony 1.4 migration throws SQLSTATE [HY000]: General error: 1005 (err 150) - doctrine:migrate fails!

Here is a situation i could not resolve by myself.
I have an existing symfony 1.4 project with database, model and etc. I want to make a migration so I've done:
./symfony cc
./symfony doctrine:generate-migrations-db
./symfony doctrine:generate-migrations-model
All classes for the migration were created, so I've tried to apply the migration by:
./symfony doctrine:drop-db
./symfony doctrine:build-db
./symfony doctrine migrate
And the migration proccess crashes. It thros an error:
- SQLSTATE[1005]: General error: 1005 Can't create table 'database.#sql-6df_301' (errno: 150). Failing Query: "ALTER TABLE product ADD CONSTRAINT "product_product_group_id_product_group_id FOREIGN KEY (product_group_id) REFERENCES product_group(id) ON DELETE CASCADE
This is strange. I have more tables with relations and they are created, but that one fails. I've check everything i can think of. The indexes types, the table types, the phase of the moon - everything seems to be OK. I've try to SET FOREIGN_KEY_CHEKS=0 to chase some ghosts, but NADA!
The error still occures.
Does anybody knows what is happening or a kind of solution?
Any suggestion?
You should not use :generate-migrations-models . Try it with the sequence
./symfony cc
./symfony doctrine:generate-migrations-db
./symfony doctrine:drop-db
./symfony doctrine:build-db
./symfony doctrine migrate
The line
./symfony doctrine:generate-migrations-models
uses the model classes to generate the migrations. It's not always a good idea, because you could have forgotten models messing things up. In order to clean those forgotten models use the following before you start those commands above.
./symfony doctrine:clean-model-files
I've cracked it up.
In a some hilarious reason the auto-generated migration classes are named like this:
1311678541_add<table-name>.php
1311678542_add<table-name>.php
1311678543_add<table-name>.php
...
13116785578_addfks.php
...
1311678579_add<table-name>.php
1311678580_add<table-name>.php
1311678582_addproductgroup.php
The 13116785578_addfks.php file appears before 1311678582_addproductgroup.php.
The file 13116785578_addfks.php containing a class which creates all relations (foreign keys and constraints), but it tries to add constraint on a non existing table (in my case product_group, which will be created last). So, the SQL error means YOU ARE TRYING TO CREATE A RELATION WITH UNEXISTING TABLE, YOU MORON! :)
My soltion is to rename the 13116785578_addfks.php to 13116785590_addfks.php as it forces the doctrine merge machine to execute it as a last step. When executed all tables are already made and MySQL server is happy!
So, what about the reason for this miss-ordering?
Probably it caused by mixi'n up the to tasks doctrine:generate-migrations-db and doctrine:generate-migrations-models,
but the Symfony's Migration tutorial isn't very clear with this.
Why I use them both?
When I done ./symfony doctrine:generate-migration-db only the half of classes for the migration was created. It is strange - there are only general tables and no related ones! So I called doctrine:generate-migrations-models.
Conclusion
Another question raises: Why doctrine:generate-migrations-db does not generate migration classes for related tables of the model?