1

我正在尝试基于 Magento 数据库结构创建一个表。我在安装过程中不断收到错误,因此我正在尝试创建与该问题相关的三个表。我不断收到 OAuth 安装错误。新版本的 Magento 在 MySQL 中将进程划分为 3 个表。所以已经创建了三个表中的两个,这是第三个表的 MySQL 脚本 - 这是运行错误的表。

DROP TABLE IF EXISTS `oauth_token`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `oauth_token` (
`entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity ID',
`consumer_id` int(10) unsigned NOT NULL COMMENT 'Consumer ID',
`admin_id` int(10) unsigned DEFAULT NULL COMMENT 'Admin user ID',
`customer_id` int(10) unsigned DEFAULT NULL COMMENT 'Customer user ID',
`type` varchar(16) NOT NULL COMMENT 'Token Type',
`token` varchar(32) NOT NULL COMMENT 'Token',
`secret` varchar(32) NOT NULL COMMENT 'Token Secret',
`verifier` varchar(32) DEFAULT NULL COMMENT 'Token Verifier',
`callback_url` varchar(255) NOT NULL COMMENT 'Token Callback URL',
`revoked` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Is Token revoked',
`authorized` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Is Token authorized',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Token creation         timestamp',
PRIMARY KEY (`entity_id`),
UNIQUE KEY `UNQ_OAUTH_TOKEN_TOKEN` (`token`),
KEY `IDX_OAUTH_TOKEN_CONSUMER_ID` (`consumer_id`),
KEY `FK_OAUTH_TOKEN_ADMIN_ID_ADMIN_USER_USER_ID` (`admin_id`),
KEY `FK_OAUTH_TOKEN_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID` (`customer_id`),
CONSTRAINT `FK_OAUTH_TOKEN_ADMIN_ID_ADMIN_USER_USER_ID` FOREIGN KEY (`admin_id`)         REFERENCES `admin_user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_OAUTH_TOKEN_CONSUMER_ID_OAUTH_CONSUMER_ENTITY_ID` FOREIGN KEY     (`consumer_id`) REFERENCES `oauth_consumer` (`entity_id`) ON DELETE CASCADE ON UPDATE     CASCADE,
CONSTRAINT `FK_OAUTH_TOKEN_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID` FOREIGN KEY (`customer_id`) REFERENCES `customer_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='OAuth Tokens';
/*!40101 SET character_set_client = @saved_cs_client */;

那么我应该怎么做或如何更改 MySQL 脚本以使其正常工作?

4

1 回答 1

2

最常见的原因是您引用的表是 MyISAM,您不能在 FK 关系中使用它们。

也可能是您的 FK 没有唯一的名称,但考虑到您的命名约定,这看起来不太可能。

If neither of those, check the columns you are referencing and make sure they have an index on them, either primary key or unique.

Finally check your data type, it must be exactly the same between both columns in the FK relationship. even differing lengths (int(10), int(11)), or signed vs unsigned will not allow you to make an FK relationship.

于 2012-08-23T21:06:51.490 回答