This is a primary key so this won't required any INDEX and a PRIMARY KEY should never be updated so is much more maintainable. If none are given, ALTER TABLE does nothing. Following the table name, specify the alterations to be made. Missing index for constraint avatarsibfk2 in the referenced table photos') mysqlsh.exe -version C:Program FilesMySQLMySQL Shell 8.0binmysqlsh.exe Ver 8.0.19 for Win64 on x8664 - for MySQL 8.0.19 (MySQL Community Server (GPL)). Renaming a table requires ALTER and DROP on the old table, ALTER, CREATE, and INSERT on the new table. 1822, 'Failed to add the foreign key constraint. So instead of teacher_name in courses, you would have ref_teacher int. To use ALTER TABLE, you need ALTER, CREATE, and INSERT privileges for the table. This won't required those INDEX and this is easier to update a teacher name if it is only in the table teacher. Just add an index on this column : ALTER TABLE teachers ADD INDEX for_index_teacher_name(teacher_name) īut I suggest you start using the ID instead of the names. Since teacher_name is not a PRIMARY KEY and has no index. The problem comes from constraint teachers FOREIGN KEY (teacher_name) references Teachers(teacher_name) ON DELETE CASCADE,Ĭonstraint courses FOREIGN KEY (course_name) references courses(course_name)Ĭur.execute("ALTER TABLE students COMMENT = '学生表' ") Students_age varchar(255) comment '学生年龄',Ĭonstraint teachers FOREIGN KEY (teacher_name) references Students_sex varchar(255) comment '学生性别', Students_name varchar(255) comment '学生姓名', Teacher_name varchar(255) comment '教师姓名',Ĭur.execute("ALTER TABLE teachers COMMENT = '教师表' ")Ĭur.execute("ALTER TABLE teachers ADD INDEX for_index_name(course_name) ")įOREIGN KEY (course_name) REFERENCES teachers(course_name) ON DELETE CASCADEĬur.execute("ALTER TABLE courses COMMENT = '课程表' ")Ĭur.execute("ALTER TABLE courses ADD INDEX for_index_name(course_name) ") Id int NOT NULL auto_increment primary key comment 'ID', When I created the students table's foreign key then the question occurred.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |