2015-07-21 53 views
-1

虽然我试图创建一个表,我得到错误无法创建表问题150.我GOOGLE了这个问题,发现这是与外键约束有关。以下是我用来创建表的代码。还用sqlfiddle来检查问题。我无法创建表格。我得到150错误

DROP TABLE IF EXISTS `catalog_category_flat_store_1`; 


/*!40101 SET @saved_cs_client  = @@character_set_client */; 
/*!40101 SET character_set_client = utf8 */; 


    CREATE TABLE `catalog_category_flat_store_1` (
    `entity_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'entity_id', 
    `parent_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'parent_id', 
    `created_at` timestamp NULL DEFAULT NULL COMMENT 'created_at', 
    `updated_at` timestamp NULL DEFAULT NULL COMMENT 'updated_at', 
    `path` varchar(255) NOT NULL DEFAULT '' COMMENT 'path', 
    `position` int(11) NOT NULL DEFAULT '0' COMMENT 'position', 
    `level` int(11) NOT NULL DEFAULT '0' COMMENT 'level', 
    `children_count` int(11) NOT NULL DEFAULT '0' COMMENT   'children_count', 
    `store_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Store Id', 
    `name` varchar(255) DEFAULT NULL COMMENT 'Name', 
    `is_active` int(11) DEFAULT NULL COMMENT 'Is Active', 
    `url_key` varchar(255) DEFAULT NULL COMMENT 'URL Key', 
    `description` text COMMENT 'Description', 
    `image` varchar(255) DEFAULT NULL COMMENT 'Image', 
    `meta_title` varchar(255) DEFAULT NULL COMMENT 'Page Title', 
    `meta_keywords` text COMMENT 'Meta Keywords', 
    `meta_description` text COMMENT 'Meta Description', 
    `display_mode` varchar(255) DEFAULT NULL COMMENT 'Display Mode', 
    `landing_page` int(11) DEFAULT NULL COMMENT 'CMS Block', 
    `is_anchor` int(11) DEFAULT NULL COMMENT 'Is Anchor', 
    `all_children` text COMMENT 'All Children', 
    `path_in_store` text COMMENT 'Path In Store', 
    `children` text COMMENT 'Children', 
    `url_path` varchar(255) DEFAULT NULL COMMENT 'Url Path', 
    `custom_design` varchar(255) DEFAULT NULL COMMENT 'Custom Design', 
    `custom_design_from` datetime DEFAULT NULL COMMENT 'Active From', 
    `custom_design_to` datetime DEFAULT NULL COMMENT 'Active To', 
    `page_layout` varchar(255) DEFAULT NULL COMMENT 'Page Layout', 
    `custom_layout_update` text COMMENT 'Custom Layout Update', 
    `available_sort_by` text COMMENT 'Available Product Listing Sort By', 
    `default_sort_by` varchar(255) DEFAULT NULL COMMENT 'Default Product Listing Sort By', 
    `include_in_menu` int(11) DEFAULT NULL COMMENT 'Include in Navigation Menu', 
    `custom_use_parent_settings` int(11) DEFAULT NULL COMMENT 'Use Parent Category Settings', 
    `custom_apply_to_products` int(11) DEFAULT NULL COMMENT 'Apply To Products', 
    `filter_price_range` int(11) DEFAULT NULL COMMENT 'Layered Navigation Price Step', 
    `thumbnail` varchar(255) DEFAULT NULL COMMENT 'Thumbnail Image', 
    PRIMARY KEY (`entity_id`), 
    KEY `IDX_CATALOG_CATEGORY_FLAT_STORE_1_STORE_ID` (`store_id`), 
    KEY `IDX_CATALOG_CATEGORY_FLAT_STORE_1_PATH` (`path`), 
    KEY `IDX_CATALOG_CATEGORY_FLAT_STORE_1_LEVEL` (`level`), 
    CONSTRAINT    `FK_CATALOG_CATEGORY_FLAT_STORE_1_STORE_ID_CORE_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE, 
    CONSTRAINT `FK_CAT_CTGR_FLAT_STORE_1_ENTT_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Catalog Category Flat (Store 1)'; 

当我点击链接错误的细节:支持事务,行级锁和外键

[变量|缓冲池| InnoDB Status]

+0

您的FK引用中的一个失败,但由于您没有提供关于表结构甚至实际错误消息的详细信息,因此我们无法帮到您。检查'显示引擎innodb状态'。输出中有一个“最后的外键错误”部分。 –

回答

0

您在“core_store”和“catalog_category_entity”之前创建catalog_category_flat_store_1。这就是你错误的原因。所以,首先,创建先决条件表,然后尝试脚本。

+0

您的意思是首先我需要创建1. catalog_category_flat_store_1 2. core_store 3. catalog_category_entity。我是对的。 –

+0

我怎样才能创建先决条件表? –

+0

雅,你首先需要创建这些表:“core_store”和“catalog_category_entity”。但你真的不需要这些表在你的业务逻辑,所以只需运行以下代码: – user3359139

0
   CREATE TABLE `catalog_category_flat_store_1` (
      `entity_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'entity_id', 
      `parent_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'parent_id', 
      `created_at` timestamp NULL DEFAULT NULL COMMENT 'created_at', 
      `updated_at` timestamp NULL DEFAULT NULL COMMENT 'updated_at', 
      `path` varchar(255) NOT NULL DEFAULT '' COMMENT 'path', 
      `position` int(11) NOT NULL DEFAULT '0' COMMENT 'position', 
      `level` int(11) NOT NULL DEFAULT '0' COMMENT 'level', 
      `children_count` int(11) NOT NULL DEFAULT '0' COMMENT   'children_count', 
      `store_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Store Id', 
      `name` varchar(255) DEFAULT NULL COMMENT 'Name', 
      `is_active` int(11) DEFAULT NULL COMMENT 'Is Active', 
      `url_key` varchar(255) DEFAULT NULL COMMENT 'URL Key', 
      `description` text COMMENT 'Description', 
      `image` varchar(255) DEFAULT NULL COMMENT 'Image', 
      `meta_title` varchar(255) DEFAULT NULL COMMENT 'Page Title', 
      `meta_keywords` text COMMENT 'Meta Keywords', 
      `meta_description` text COMMENT 'Meta Description', 
      `display_mode` varchar(255) DEFAULT NULL COMMENT 'Display Mode', 
      `landing_page` int(11) DEFAULT NULL COMMENT 'CMS Block', 
      `is_anchor` int(11) DEFAULT NULL COMMENT 'Is Anchor', 
      `all_children` text COMMENT 'All Children', 
      `path_in_store` text COMMENT 'Path In Store', 
      `children` text COMMENT 'Children', 
      `url_path` varchar(255) DEFAULT NULL COMMENT 'Url Path', 
      `custom_design` varchar(255) DEFAULT NULL COMMENT 'Custom Design', 
      `custom_design_from` datetime DEFAULT NULL COMMENT 'Active From', 
      `custom_design_to` datetime DEFAULT NULL COMMENT 'Active To', 
      `page_layout` varchar(255) DEFAULT NULL COMMENT 'Page Layout', 
      `custom_layout_update` text COMMENT 'Custom Layout Update', 
      `available_sort_by` text COMMENT 'Available Product Listing Sort By', 
      `default_sort_by` varchar(255) DEFAULT NULL COMMENT 'Default Product Listing Sort By', 
      `include_in_menu` int(11) DEFAULT NULL COMMENT 'Include in Navigation Menu', 
      `custom_use_parent_settings` int(11) DEFAULT NULL COMMENT 'Use Parent Category Settings', 
      `custom_apply_to_products` int(11) DEFAULT NULL COMMENT 'Apply To Products', 
      `filter_price_range` int(11) DEFAULT NULL COMMENT 'Layered Navigation Price Step', 
      `thumbnail` varchar(255) DEFAULT NULL COMMENT 'Thumbnail Image', 
      PRIMARY KEY (`entity_id`), 
      KEY `IDX_CATALOG_CATEGORY_FLAT_STORE_1_STORE_ID` (`store_id`), 
      KEY `IDX_CATALOG_CATEGORY_FLAT_STORE_1_PATH` (`path`), 
       KEY `IDX_CATALOG_CATEGORY_FLAT_STORE_1_LEVEL` (`level`) 
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Catalog Category Flat (Store 1)'; 
+0

我可以知道解释吗? –

+0

我只是从表定义中删除外键约束。正如你所说,你实际上不知道这些表格是什么。这就是为什么我猜你可能不需要他们。 – user3359139

相关问题