为什么Mysql给我错误1280“错误的索引”

任何人都可以解释为什么Mysql给我错误1280(“fk_chart_aid_aid’的错误索引”)错误,当我尝试创建“帐户图表”表时.我在这里完全糊涂了.我该如何解决这个问题,以便创建表格? “ACCOUNT”表已存在于数据库中并且其中包含数据.

谢谢您的帮助.

MYSQL Server版本:5.1.54

账户表:

DROP TABLE IF EXISTS `rst`.`acctg_chart_of_accounts` ;
CREATE  TABLE IF NOT EXISTS `rst`.`acctg_chart_of_accounts` (
  `acctg_chart_of_accounts_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `account_id` INT UNSIGNED NOT NULL ,
  `account_nbr` VARCHAR(45) NULL ,
  `description` VARCHAR(45) NULL ,
  `account_type` INT UNSIGNED NULL ,
  `commissionable` TINYINT UNSIGNED NULL ,
  `hidden` TINYINT UNSIGNED NULL ,
  `deduct_balance_from_owner_check` TINYINT UNSIGNED NULL ,
  PRIMARY KEY (`acctg_chart_of_accounts_id`) ,
  CONSTRAINT `fk_chart_aid_aid`
    FOREIGN KEY (`account_id` )
    REFERENCES `rst`.`account` (`account_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)    
ENGINE = InnoDB;
CREATE INDEX `fk_chart_aid_aid` ON `rst`.`acctg_chart_of_accounts` (`account_id` ASC) ;

帐户表正在参考:

CREATE TABLE IF NOT EXISTS `account` (
  `account_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `account_status_id` int(10) unsigned NOT NULL,
  `company_name` varchar(155) DEFAULT NULL,
  `address1` varchar(155) DEFAULT NULL,
  `address2` varchar(155) DEFAULT NULL,
  `city` varchar(155) DEFAULT NULL,
  `state` varchar(155) DEFAULT NULL,
  `zip` varchar(45) DEFAULT NULL,
  `country` varchar(255) DEFAULT NULL,
  `work_phone` varchar(45) DEFAULT NULL,
  `mobile_phone` varchar(45) DEFAULT NULL,
  `time_zone` varchar(45) DEFAULT NULL,
  `subdomain` varchar(155) DEFAULT NULL,
  `cname_URL` varchar(255) DEFAULT NULL,
  `promotion_code` varchar(45) DEFAULT NULL,
  `can_we_contact_you` tinyint(4) DEFAULT NULL COMMENT '0=false, 1=true',
  `units_managed_nbr` varchar(10) DEFAULT NULL,
  `a_hear_about_us_list_id` tinyint(3) unsigned DEFAULT NULL COMMENT 'populated from dropdown list.',
  `receive_special_offers` tinyint(4) DEFAULT NULL,
  `receive_announcements` tinyint(4) DEFAULT NULL,
  `receive_newsletter` tinyint(4) DEFAULT NULL,
  `create_ts` timestamp NULL DEFAULT NULL,
  `expires` timestamp NULL DEFAULT NULL,
  `storage_capacity` varchar(255) DEFAULT NULL COMMENT '1073741824 = 1GB',
  `logo` varchar(455) DEFAULT NULL,
  `max_active_connections` int(11) DEFAULT '3',
  `_product_id` int(11) DEFAULT NULL,
  `report_footer` varchar(455) DEFAULT NULL,
  `welcome_dialog` tinyint(4) DEFAULT '1',
  `ARB_subscription_id` int(11) DEFAULT NULL,
  `trashbin` tinyint(4) NOT NULL DEFAULT '1',
  PRIMARY KEY (`account_id`),
  KEY `fk_account_account_status_id` (`account_status_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=58 ;
最佳答案
您是在CREATE TABLE语句之后,还是在后续的CREATE INDEX之后得到错误?

看起来您正在尝试命名FOREIGN KEY约束和INDEX fk_chart_aid_aid.尝试为其中任何一个选择不同的名称.

此外,在帐户表中,account_id是INT(10).还尝试将acctg_chart_of_accounts中的列定义更改为:

`account_id` INT(10) UNSIGNED NOT NULL ,

虽然,我认为mysql默认类型INT到INT(10)无论如何…

转载注明原文:为什么Mysql给我错误1280“错误的索引” - 代码日志