I have two databases, tvguide and episodes1.
Both are InnoDB, and I use Phpmyadmin to edit them.
I tried creating a foreign key between the "episode" field of episodes1 and tvguide, and this error message came up:
Error creating foreign key (check data types) : episode
How can I fix this and ensure both tables join? I have InnoDB set for both databases, so this shouldn't happen, but why?
It may be that you have defined the 'episodes' column differently in each table. That could cause the operation to fail. Perhaps you could post (possibly trimmed versions of) your table definitions here. Then we can say for certain.
Related
I set my tables to InnoDB and can enter the relation view. But I only can add constraints no relations. What causes the problem?
Server version: 5.7.14 - MySQL Community Server (GPL)
phpMyAdmin Version: 4.6.4
WampServer Version: 3.0.6
Here a picture how I expect the view to be, the table "Internal relations" is missing:
Q: "I only can add constraints no relations. What causes the problem?"
A: I don't see any problematic behavior is being reported.
I see a description of the steps you've taken, and I'm guessing that the results of those steps aren't meeting your expectations.
If you could clarify what you expect, we might be able to help.
Briefly...
With InnoDB, a "relationship" between two tables can be expressed and enforced by creating a FOREIGN KEY constraint.
In relational database theory, a "relation" is a set of tuples. In an RDBMS, a "relation" is implemented as a TABLE.
If there was description of what you are attempting to achieve, and a more precise description of the problematic behavior you are observing, it would be possible to give some assistance.
EDIT
With InnoDB, we can use foreign keys defined in the database to represent the relationships between tables. Those are stored in InnoDB table definitions.
The PHPMyAdmin "internal relations" is used for MyISAM tables, which don't support foreign keys.
Verify that PHPMyAdmin is configured to store the "internal relations". It stores the configuration in a table named pma__relation. The actual table name is specified in the configuration of PHPMyAdmin.
https://docs.phpmyadmin.net/en/latest/config.html
If that feature is enabled, there should be a line like this in the configuration file:
$cfg['Servers'][$i]['relation'] = 'pma__relation';
(Consult the documentation for the version of PHPMyAdmin you are running.)
And verify that the pma__relation table exists in your database.
If everything looks to be configured correctly, then I would test the feature with a couple of test tables which use ENGINE=MYISAM, and see if it's working for those tables.
I don't know whether that feature is supposed to work for tables with storage engines other than MYISAM. I don't know if it works with ENGINE=INNODB tables.
I am trying to run some basic CREATE TABLE statements for my Databases course project and am getting some strange errors.
When I create the table Manuf it runs fine, but when I try to create the next table, Order, using the same syntax, it does not work.
Also, when I try to create this table, Items, I get an errno: 150. I believe this has to do with my foreign key creation, but I am not exactly sure. Here is a screenshot of that.
I am fairly new to using MySQL so any advice would be greatly appreciated, thank you.
The error on the Order table is caused by ORDER being a reserved word. You can specify it as `Order` with the backticks, but it's better if you choose a different name altogether.
The error 150 is related to the foreign key. The keys must be absolutely identical - the exact same definition, or the FK will fail with error 150.
Also, there must be an available index with that key definition or one compatible (see Kai Baku's example in the comment on the MySQL manual page). The same fields indexed in a different order will fail.
To begin with, check how those keys are defined in the origin tables. For example:
test1 varchar(50) not null
test2 varchar(50)
will not be compatible. I think that even a different collation is enough to throw FK off kilter (but this I haven't checked. The rest I'm sure of, from my personal bitter unexperience).
UPDATE: I forgot to mention, if you use InnoDB tables and issue the SHOW ENGINE INNODB STATUS, the blurb that comes out will contain a much better explanation of why the FK failed, somewhere about one third from top.
I have a database that I built a while back. Every table in the database is InnoDb. Several tables had foreign key constraints, and I set them up for On Delete = Cascade. When I was using an earlier version of phpmyadmin, working with these was simple: I'd just go to the Structure tab of a table, click the Relation View link, and as long as I had the correct indexes set up on the correct columns, I could set the foreign keys as I saw fit.
Since upgrading to version 4, it's become a nightmare. For some tables, I go to the relation view and everything is just fine. But for others--even when they already have foreign key constraints set--I can't see any options for working with them.
To make matters worse, I've even tried dropping the indexes and re-adding them, only to be given the following error: Cannot drop index [index_name]: needed in a foreign key constraint. So unless I'm mistaken, the constraint is there, but phpmyadmin is refusing to show it to me.
Is there something I have to do to make them show up again? This is extremely frustrating to say the least: something that worked just fine before now does not thanks to an upgrade.
OK, after playing around with the tables a bit, I figured out what's going on. The only time the foreign key constraint options don't show up are when the table names contain capital letters. Very frustrating to say the least.
I just filed a bug report for phpmyadmin: https://github.com/phpmyadmin/phpmyadmin/issues/11461
It should be an easy fix.
happened to me because i used '&" in the database name.
In my case it is that I used two columns (A and B) both as foreigns keys to other tables then I also used a composite unique for ([A, B]), phpMyAdmin does not show the existed foreign index of column A but does show that for column B.
My system version are as follows:
Server version: 5.7.30 - MySQL Community Server (GPL)
My issue is similar to this question:
ALTER TABLE error
My message is:
#1025 - Error on rename of './balance/#A' to './balance/#B' (errno: -1)
Anytime I want to alter the table I get a cryptic message that it can't be done (like the above question).
All the research I've done points to an issue with foreign keys referencing the table in question. My table has no foreign keys and is quite simple, just a unique primary key.
MySQL documentation for this issue is spartan and does not give any details. I've had an issue in the past with permissions, and I couldn't even see the contents of innoDB tables, but I resolved that. I wonder if this could be some sort of permission issue. Using MySQL 5.5.15-log.
This issue was resolved. In my case it had to with with having forced recovery for my innodb tables enabled. I found it by looking in my log. When forced recovery is on, apparently no changes are allowed to the DB.
Now, the fact that it generated a foreign key error in my InnoDB engine log with no FKs is another issue.....I posted it as a bug to MySQL.
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