Laravel relations across different databases - mysql

I am currently trying to do the following in a Laravel 5.4 project
$this->belongsToMany(Module::class,'platform_modules_acquired', 'platform_id', 'module_id');
Now the module class pulls from a table in the admin database while the table platform_modules_acquired is in the clients database. When I try to run the above code I get an error saying platform_modules_acquired table can't be found in the admin database.
I tried changing the above request by saying that the table is clients.platform_modules_acquired but still not finding the table. Also I tried appending ->using('PlatformModules::class') but still getting the same error...
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'admin.plataformas_modulos_contratados' doesn't exist (SQL: select 'module' from 'modules' inner join 'platform_modules_acquired' on 'modules'.'id' = 'platform_modules_acquired'.'module_id' where 'platform_modules_acquired'.'platform_id' = 187)
How could I go about telling this relation to look in the clients database for the table?

You can use a connection inside the relation like this:
$this->belongsToMany(Module::class,'clients.platform_modules_acquired', 'platform_id', 'module_id');

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

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.

Magento 2.1.7 order saving error: SQLSTATE[42S02]:

I have just tried to add a custom order for testing purposes but I get this error:
Order saving error: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento_.sequence_order_1' doesn't exist, query was: INSERT INTO `sequence_order_1` () VALUES ()
How can I solve this issue?
The error strong said that table hast not found in database.
so the things that you can do.
1.check the database is table exist or not
2.if table exist then look properly is your table name correct in the script

I receive this error when I run the module

Magneto website:
SQLSTATE[42S02]: Base table or view not found: 1146 Table mysite_mage1.catalog_product_entity doesn't exist
This table exists but has a different name in my data base and it is one category further.
My table is named
mysite_mage1.mage_catalog_product_entity
I don't have access to the module's code, I cant change the name of the table it is looking for, I believe I cant I change the name of the table in mySQL database.

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.