Mysql 我无法创建表。我有150个错误

Mysql 我无法创建表。我有150个错误,mysql,sql,phpmyadmin,Mysql,Sql,Phpmyadmin,当我试图创建一个表时,出现了无法创建表的错误150。我在谷歌上搜索了这个问题,发现这与外键约束有关。下面是我用来创建表的代码。还使用SQLFIDLE检查问题 DROP TABLE IF EXISTS `catalog_category_flat_store_1`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */;

当我试图创建一个表时,出现了无法创建表的错误150。我在谷歌上搜索了这个问题,发现这与外键约束有关。下面是我用来创建表的代码。还使用SQLFIDLE检查问题

 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)';
单击错误链接的详细信息时:支持事务、行级锁定和外键


[Variables | Buffer Pool | InnoDB Status]

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

您的多个FK引用失败,但由于您没有提供表结构的详细信息,甚至没有提供实际的错误消息,因此我们无法帮助您。选中“显示引擎innodb状态”。输出中有一个“last foreign key error”(最后一个外键错误)部分。您的意思是首先我需要创建1。目录\类别\平面\商店\ 1 2。core_商店3。目录\类别\实体。我是对的。我怎样才能创建先决条件表呢?是的,首先需要创建这些表:“核心存储”和“目录类别实体”。但是在您的业务逻辑中确实不需要这些表,所以只需运行以下代码:我可以知道解释吗?我只是从表定义中删除了外键约束。正如你所说,你实际上不知道那些桌子是什么。这就是为什么我猜你可能不需要它们。
             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)';