Mysql5.7 failed to create a foreign key! Have you been torturing me all day?

 

  mysql  
create table trkr_admin(
    id tinyint unsigned not null auto_increment primary key comment "ID",
    name CHAR(30) not null default "" comment "",
    cname CHAR(30) not null default "" comment "",
    password char(32) not null default "" comment "",
    status  tinyint not null default "1" comment " 1 2",
    UNIQUE(name),
    UNIQUE(cname),
    index(name)
)engine=InnoDB charset=utf8mb4;

create table trkr_article(
    id int unsigned not null auto_increment primary key comment "ID",
    title char(20)  not null default "" comment "",
    content varchar(16000) not null default " "   comment "",
    bind_adminname_id tinyint unsigned not null  comment "",
    FOREIGN KEY(bind_adminname_id) REFERENCES trkr_admin(id),
    FULLTEXT (title,content) WITH PARSER ngram 
)engine=InnoDB charset=utf8mb4;

error message : ERROR 1215 (HY000): Cannot add foreign key constraint

)
Apr.02,2021

well, it's quite common for a day or two, but of course the sooner you solve it, the better. And when you encounter this kind of problem, it is best to put the error information and related code first if there is an error so that it is convenient for everyone to help you find the problem. On the foreign key this piece, I do not involve much (not not much, but there is no actual operation at all, generally through the program to control the sql. ) related links


CREATE TABLE `trkr_admin` (
    `id` TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `name` CHAR(30) NOT NULL DEFAULT '' COMMENT '',
    `cname` CHAR(30) NOT NULL DEFAULT '' COMMENT '',
    `password` CHAR(32) NOT NULL DEFAULT '' COMMENT '',
    `status` TINYINT(4) NOT NULL DEFAULT '1' COMMENT ' 1 2',
    PRIMARY KEY (`id`),
    UNIQUE INDEX `name` (`name`),
    UNIQUE INDEX `cname` (`cname`)
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

CREATE TABLE `trkr_article` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `title` CHAR(20) NOT NULL DEFAULT '' COMMENT '',
    `content` VARCHAR(16000) NOT NULL DEFAULT ' ' COMMENT '',
    `bind_adminname_id` TINYINT(3) UNSIGNED NOT NULL COMMENT '',
    PRIMARY KEY (`id`),
    INDEX `bind_adminname_id` (`bind_adminname_id`),
    CONSTRAINT `trkr_article_ibfk_1` FOREIGN KEY (`bind_adminname_id`) REFERENCES `trkr_admin` (`id`),
    FULLTEXT (title,content) WITH PARSER ngram
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

does it look like the sub-table field index is not built? Or is there any problem with your parser ngram execution

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b43e8a-2c6b6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b43e8a-2c6b6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?