-1

i have this tables :

CREATE TABLE `maht_subs` (
`smaht_code` int(11) NOT NULL,
`smaht_name` varchar(50) DEFAULT NULL,
`smaht_mahbert` int(11) DEFAULT NULL,
`smaht_type` varchar(50) DEFAULT NULL,
`point_smaht` varchar(40) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

and

CREATE TABLE `users` (
`number` int(11) NOT NULL,
`username` varchar(50) DEFAULT NULL,
`userlast` varchar(50) DEFAULT NULL,
`userid` varchar(10) NOT NULL,
`mgma_no` int(11) NOT NULL,
`password` text,
`useradmin` tinyint(1) DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

when i exc this query

create table maht_grades
(
id int AUTO_INCREMENT,
userid int,
smaht_code int,
moaad varchar(50),
date date,
grade_magen varchar(50),
grade_final varchar(50),
mahbert text,
constraint pk45 primary key(id),
constraint fko foreign key(userid) references users(number),
constraint fk13 foreign key(smaht_code) references maht_subs(smaht_code)
);

i get this message :

1005 - Can't create table ministry.maht_grades (errno: 150 "Foreign key constraint is incorrectly formed")

i checked the data type from tables users and maht_subs , but nothing happen

can anyone help me to fix it ?

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
marm saeed
  • 11
  • 4

1 Answers1

0

When creating a foreign key, the column referencing should have the exact same type as the column it references. Change userid and smaht_code to int(11) instead of int, and you should be OK.

Mureinik
  • 297,002
  • 52
  • 306
  • 350