pgloader MySQL to Postgres: Disable FK for specified tables - mysql

I'm trying to migrate mysql database to postgres using pgloader.
Some tables in the current mysql database have foreign keys, but referential integrity is broken (based on data in those tables). I need to ignore FK constraint for those tables.
There is an option to disable foreign keys for all tables while migrating the database
WITH no foreign keys
But I need to disable FK-s only for a specified list of tables and preserve FK-s for all other tables. I can't find anything related to this case in the documentation.
How it could be achieved?
The only option I've found for now - is to migrate the database in two steps:
migrate all tables excluding those for which FK-s should be ignored
migrate only tables for which FK-s should be ignored with no foreign keys option
Is there a simpler way?

Related

Foreign keys vanishes after froward engineer on Mysql Workbench

There was a existing MySQL database. I have reversed engineer the db into MySQL Workbench then created some tables and placed some relationship among tables.
At the end I forward engineered the database. Then I observed the db from phpmyadmin, in that db the new tables and other changes have taken places but foreign keys does not seems to be added. What the problem here???? What should I do?
Foreign keys are only supported by very few table engines. What's yours? Set all your tables to InnoDB and your foreign keys will be kept.

MySQL DB Foreign Key

What are the pros and cons of creating table relationships in a MySQL database using queries (JOINS) as opposed to doing it with DDL using Foreign key and referential integrity constraints? I have received a database that has not relationships (No FK) on its tables to identify relationships among tables. The relationships are being created on JOINS when data is being queried.
The main reason for using foreign keys is that data is always consistent in the database. This is "independent" from joins - when you use foreign keys you still need to use joins.
In MySQL it also has a nice side effect: if you use foreign keys, you have to define indexes which might speed up queries.
But with foreign keys you can make sure, that the row which you are referring must exist in the database. See https://en.wikipedia.org/wiki/Foreign_key.

How to define foreign key in two different databases in MySQL and phpMyAdmin

I have a large database structure.
My hosting plan says I can have unlimited databases but each database is limited to 1 GB.
How can I define a foreign key in one database table to reference a table in another database using MySQL and phpMyAdmin?
In the upcoming phpMyAdmin 4.1 (now released as 4.1.0-alpha2), you go to Structure for a table, then Relation view. You then see a panel where you can select other databases for your foreign keys.

Access not importing relationships for MySQL linked tables

I have successfully linked my MySQL database with my Access database file. Everything is working fine except the relationships in the MySQL database are not appearing in Access.
I have made a plenty of relationships in the MySQL tables using foreign keys, but these relationships are not reflected in Access. Kindly help me to import the relationships from the MySQL database into Access.
Software I'm using: MySQL version 5, Microsoft Office 2013, Access file format: .accdb
While it is true that the MySQL foreign key constraints don't show up by default in the Relationships tab in Access, those constraints are still in place in MySQL and are still enforced for linked tables.
For example, say I have two MySQL tables, [customers] and [orders], with a foreign-key constraint on [orders]. If I link to those tables in Access and I try to insert a row into my [orders] linked table where the [customerID] does not match a [customerID] in my [customers] linked table the insert fails:
ODBC --insert on a linked table 'orders' failed.
[MySQL][ODBC 5.2(w) Driver][mysqld-5.5.29-0ubuntu0.12.04.2]Cannot add or update a child row: a foreign key constraint fails (`zzzTest`,`orders`, CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`customerID`) REFERENCES `customers` (`customerID`)) (#1452)
You can go into the Relationships tab in Access and create "Access-side" relationships for the MySQL tables...
...but notice that the "Enforce Referential Integrity" options are greyed out because that is a function of the database setup at the server, not in Access. So really, the only benefits that the "Access-side" relationships would offer are:
"documentation" of the relationships (which you could get from a database diagram generated against the MySQL database), and
"automatic" joins between the linked tables in the Access query designer (which can also happen without [Access] Relationships if tables have columns with the same name).
It's up to you to decide whether it would be worth the trouble to create those "Access-side" relationships.
Since this is cross databases, it may have to recreated manually.
Check out this one, Importing .sql into MS Access using OBDC

What are the "Internal Relations" defined in phpMyAdmin?

In the phpMyAdmin relation view, there is a column for "internal relation" right next tor "foreign key constraint". I know what foreign keys are used for in mySQL, but I've never heard of internal relations.
Is this a phpMyAdmin thing?
This is a phpmyadmin internal mechanism to manage relationship between tables.
This feature is actually useful for MYISAM tables which don't support foreign keys and constraints.
By defining internal relations in phpmyadmin you link tables together which otherwise can't be linked. These information are stored in a phpmyadmin specific table inside your MySQL server (phpmyadmin.PMA_relation).
However this is just a phpmyadmin internal definition and has no effect on mysql itself (no foreign key constraints or referential integrity are enforced).
See here for additional information.