Foreign keys vanishes after froward engineer on Mysql Workbench - mysql

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.

Related

pgloader MySQL to Postgres: Disable FK for specified tables

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?

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

NO foreign keys created though I created them . It shown me no error while executing the query. but now showing no foreign keys for my schema

I executed script related to create my database ..it executed successfully. but no foreign keys created . I am using cent os . mysql 5.0.
If the DB engine is one that does not support FK, it will show you no errors, but won't create them. For example, MyIsam.
Choose InnoDB as the table type to be able to create FK on it.
are the tables in MyISAM instead of InnoDB?
MyISAM don't support foreign keys.

foreign key constraint not respected

I have recently switched jobs and at this new company we are using MySQL. I don't have any expereince with MySQL, although I have used SQL Server and Oracle for over 4 years now.
Now the strange thing I see with MySQL is that it does not seem to resepect some of the basic things like Foreign Key Constraints (meaning a column is a foregin key but i can insert any value here no matter if it's present in the other table where this FK related to). Now I know in SQL Server there is this concept of a NOCHECK foriegn key constraint but the guy at new company responsible for MySQL db say that not respecting a FK is a normal thing in MySQL and it does not need to have any special settings (like NOCHECK FK constraint).
I fail to understand that in a database system how can you ensure referential integirty without having these basic checks in place. I am not sure if the local mySQL "expert" know it well or it's just that mySQL really does not respect FK rules. Any thoughts?
Check that your tables are using the InnoDB engine. When using the MyISAM engine (which was the default until recently), foreign keys declarations are not enforced.
MySQL have different DB Engines -
MyISAM - default, no FK support
InnoDB - have FK support - but no fulltext search like in MyISAM
On both engines you can create table and try to create FK, but MyISAM will simply ignore it.
Also, make sure foreign keys are being enforced. For some reason they weren't on mine, leading to one week of headache!
Check:
SELECT ##FOREIGN_KEY_CHECKS
Set:
SET FOREIGN_KEY_CHECKS=1