error when creating constraint on table.

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
charbel
Posts: 15
Joined: Fri 02 May 2008 06:42

error when creating constraint on table.

Post by charbel » Mon 02 Jun 2008 06:36

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?

jkuiper_them
Posts: 28
Joined: Thu 20 Dec 2007 14:48

Post by jkuiper_them » Mon 02 Jun 2008 13:11

you have forgot something:

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;
If you tested your SQL on the database, you will see an error in your query.

charbel
Posts: 15
Joined: Fri 02 May 2008 06:42

Post by charbel » Mon 02 Jun 2008 13:24

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?

jkuiper_them
Posts: 28
Joined: Thu 20 Dec 2007 14:48

Post by jkuiper_them » Mon 02 Jun 2008 13:33

Nothing. I think your table is corrupted.
Does it work if you create a new table with the same fields and try to create a foreign key?

charbel
Posts: 15
Joined: Fri 02 May 2008 06:42

Post by charbel » Mon 02 Jun 2008 14:12

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)

jkuiper_them
Posts: 28
Joined: Thu 20 Dec 2007 14:48

Post by jkuiper_them » Mon 02 Jun 2008 14:35

Where is you database running?
Do you have permission to create the index.
It seems that the permission on the file is not correct to create the index.

Try it in the DBDEMOS database as administrator.
I Tried also, but couldn't reproduce the error.
What do they say on the MySQL forum?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Mon 02 Jun 2008 15:06

The reason of the problem is that character sets for the Supplier_code column is not defined explicitly when character set for Ledger_number is defined as utf8. You should define character set in the same way for both columns to resolve this problem.

Post Reply