2015-07-21 44 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

相關問題