error when creating constraint on table.
error when creating constraint on table.
hi.
im facing an error when executing a script in my application to create constraints on tables . the error msg is :
Script line: 1 Can't create table '.\jmg_acc2008\#sql-3ac_1.frm' (errno: 150)
jmg_acc2008 is my database name.
here is an example on my code:
on btn click :
MyScript1.Execute;
and the script sql :
alter table purchases
add constraint `purchasessupplier_code` foreign key `purchasessupplier_code`(`supplier_code`)
references `suppliers`(`ledger_number`)
on delete restrict;
what is wrong?
im facing an error when executing a script in my application to create constraints on tables . the error msg is :
Script line: 1 Can't create table '.\jmg_acc2008\#sql-3ac_1.frm' (errno: 150)
jmg_acc2008 is my database name.
here is an example on my code:
on btn click :
MyScript1.Execute;
and the script sql :
alter table purchases
add constraint `purchasessupplier_code` foreign key `purchasessupplier_code`(`supplier_code`)
references `suppliers`(`ledger_number`)
on delete restrict;
what is wrong?
-
jkuiper_them
- Posts: 28
- Joined: Thu 20 Dec 2007 14:48
you have forgot something:
If you tested your SQL on the database, you will see an error in your query.
Code: Select all
ALTER TABLE `dbdemos`.`purchases` ADD CONSTRAINT `FK_purchases_1` FOREIGN KEY `FK_purchases_1` (`suppl_ID`)
REFERENCES `supplier` (`suppl_ID`)
ON DELETE RESTRICT
ON UPDATE RESTRICT;
i did tested my code in mysql query browser and still have the same error.
this is my code :
ALTER TABLE `jmg_acc2008`.`purchases` ADD CONSTRAINT `FK_Purchase_1` FOREIGN KEY `FK_Purchase_1` (`supplier_code`)
REFERENCES `suppliers` (`ledger_number`)
ON DELETE RESTRICT
ON UPDATE RESTRICT;
same error msg : Can't create table '.\jmg_acc2008\#sql-3ac_1e.frm' (errno: 150)
what code i missed?
this is my code :
ALTER TABLE `jmg_acc2008`.`purchases` ADD CONSTRAINT `FK_Purchase_1` FOREIGN KEY `FK_Purchase_1` (`supplier_code`)
REFERENCES `suppliers` (`ledger_number`)
ON DELETE RESTRICT
ON UPDATE RESTRICT;
same error msg : Can't create table '.\jmg_acc2008\#sql-3ac_1e.frm' (errno: 150)
what code i missed?
-
jkuiper_them
- Posts: 28
- Joined: Thu 20 Dec 2007 14:48
Dear sir,
following ur suggestion about corrupted table, i created a new schema, and created the 2 tables . im working in the sql query browser.
here is the code i used :
DROP TABLE IF EXISTS `test_acc2008`.`purchases`;
CREATE TABLE `test_acc2008`.`purchases` (
`Purchase_id` double NOT NULL,
`Supplier_code` varchar(10) default NULL,
PRIMARY KEY (`Purchase_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `test_acc2008`.`suppliers`;
CREATE TABLE `test_acc2008`.`suppliers` (
`Ledger_number` varchar(10) character set utf8 NOT NULL,
`Ledger_name` varchar(50) default NULL,
PRIMARY KEY (`Ledger_number`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `test_acc2008`.`purchases` ADD CONSTRAINT `FK_Purchase_1` FOREIGN KEY `FK_Purchase_1` (`supplier_code`)
REFERENCES `suppliers` (`ledger_number`)
ON DELETE RESTRICT
ON UPDATE RESTRICT;
same error still appear: Can't create table '.\test_acc2008\#sql-3ac_3b.frm' (errno: 150)
following ur suggestion about corrupted table, i created a new schema, and created the 2 tables . im working in the sql query browser.
here is the code i used :
DROP TABLE IF EXISTS `test_acc2008`.`purchases`;
CREATE TABLE `test_acc2008`.`purchases` (
`Purchase_id` double NOT NULL,
`Supplier_code` varchar(10) default NULL,
PRIMARY KEY (`Purchase_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `test_acc2008`.`suppliers`;
CREATE TABLE `test_acc2008`.`suppliers` (
`Ledger_number` varchar(10) character set utf8 NOT NULL,
`Ledger_name` varchar(50) default NULL,
PRIMARY KEY (`Ledger_number`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `test_acc2008`.`purchases` ADD CONSTRAINT `FK_Purchase_1` FOREIGN KEY `FK_Purchase_1` (`supplier_code`)
REFERENCES `suppliers` (`ledger_number`)
ON DELETE RESTRICT
ON UPDATE RESTRICT;
same error still appear: Can't create table '.\test_acc2008\#sql-3ac_3b.frm' (errno: 150)
-
jkuiper_them
- Posts: 28
- Joined: Thu 20 Dec 2007 14:48