我无法创建表格。我得到150错误

时间:2015-07-21 14:55:20

标签: mysql sql phpmyadmin

当我尝试创建一个表时,我得到错误无法创建表问题150.我搜索了这个问题,发现这与外键约束有关。下面是我用来创建表的代码。还使用sqlfiddle来检查问题。

 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状态]

2 个答案:

答案 0 :(得分:0)

您正在“core_store”和“catalog_category_entity”之前创建catalog_category_flat_store_1。这就是你得到错误的原因。因此,首先,创建必备表,然后尝试脚本。

答案 1 :(得分: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)';