| Problem with insertion in table with two foreigns [message #87942] |
Fri, 06 November 2009 22:01  |
masterix Messages: 41 Registered: September 2008 |
Member |
|
|
Hi,
I have a table:
order:
id: ~
user_id: { type: integer, foreignTable: sf_guard_user, foreignReference: id, required: true }
company_id: { type: integer, required: true, foreignTable: sf_guard_user, foreignReference: id }
Unfortunately when I try to add a new record in module with admin-generator ( generated form ) I get such error:
| Quote: | Unable to execute INSERT statement. [wrapped: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order (`ID`,`USER_ID`,`COMPANY_ID`) VALUES (NULL,6,9)' at line 1]
|
I suppose it is connected with two foreign keys to the same table. I use propel and there are some users in DB. How can I solve this problem?
Regards,
masterix
[Updated on: Fri, 06 November 2009 22:04]
|
|
|
|
|
|
|
|
|
|
|
| Re: Problem with insertion in table with two foreigns [message #87984 is a reply to message #87942 ] |
Sat, 07 November 2009 20:13   |
masterix Messages: 41 Registered: September 2008 |
Member |
|
|
Unfortunately I'm getting such error:
| Quote: | CREATE TABLE `order`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`user_id` INTEGER NOT NULL,
`company_id` INTEGER NOT NULL,
PRIMARY KEY (`id`),
INDEX `FI_sf_guard_user_composite` (`user_id`,`company_id`),
CONSTRAINT `FK_sf_guard_user_composite`
FOREIGN KEY (`user_id`,`company_id`)
REFERENCES `sf_guard_user` (`id`,`id`)
)Type=InnoDB
[propel-sql-exec] SQLSTATE[HY000]: General error: 1005 Can't create table './jedz/order.frm' (errno: 150)
|
I tried to find something in google but it didn't help. SHOW ENGINE INNODB STATUS command tells:
| Quote: | LATEST FOREIGN KEY ERROR
------------------------
091107 20:02:20 Error in foreign key constraint of table jedz/order:
FOREIGN KEY (`user_id`,`company_id`)
REFERENCES `sf_guard_user` (`id`,`id`)
)Type=InnoDB:
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-co nstraints.html
for correct foreign key definition.
| But ID in sf_user_guard is the primary key so it's indexed...
No idea what to do now, any hints?
In general it created one foreign key but I need two of them actually. Because they are separate.
@mugen: I have new order form with following input:<input type="hidden" name="order[id]" id="order_id" />
Should it be there?
Regards,
masterix
[Updated on: Sat, 07 November 2009 20:19]
|
|
|
| Re: Problem with insertion in table with two foreigns [message #88845 is a reply to message #87942 ] |
Sun, 22 November 2009 17:18  |
masterix Messages: 41 Registered: September 2008 |
Member |
|
|
I still can't solve the problem. I've noticed that if I use phpMyAdmin do add a record to order table there are quotes added to integer values whereas propel has no quotes in sql query. Why?
INSERT INTO `order` (`id`, `user_id`, `company_id`) VALUES (NULL, '4', '2');
I think there shouldn't be any quotes.
Regards,
masterix
|
|
|