scenario
Student table S (SNO, SNAME, SAGE), class schedule C (CNO, CNAME)
When the course selection table (SC) is created, set (SNO, CNO) as the primary key and SNO and CNO as the foreign keys
drop table if exists sc1;
create table sc1(
sno varchar(10),
cno varchar(10),
grade numeric,
primary key(sno,cno),
foreign key(sno) references s(sno),
foreign key(cno) references c(cno)
);
Error warning:
The solution
1. Check whether the types and sizes of foreign key fields in SC table are exactly the same as those in S table C table
2. One of the foreign keys you are trying to reference has no index or is not a primary key. If one of the foreign keys is not a primary key, you must create an index for it.
3, one or two tables are MyISAM engine table, if you want to use foreign key constraints, must be InnoDB engine
The error of the author is that cNO is not set as primary key in Table C, which can be solved by setting it once
Read More:
- About error 1005 (HY000) in MySQL: can’t create table ‘_______ ‘(errno: 150) fool’s plan
- SQL exception handling – MySQL error 1005 (HY000): can’t create table ‘TMP’ (errno: 13)
- MySQL error: 1005 can’t create table (error: 150)
- MySQL – ERROR 1146 (42S02): Table ‘mysql.user’ doesn’t exist
- DB2 create table error – 104 42601 illegal symbol encountered in SQL statement
- MySQL partitions the existing tables of the data table
- mysql Error Code: 1022. Can’t write; duplicate key in table `xxx`
- Django. DB. Utils. Programmingerror: (1146, “table * doesn’t exist”) causes and Solutions
- mysql ERROR 1050 (42S01): Table already exists
- Question: cannot create windows service for mysql.error : 0 (install MySQL)
- The problem of MySQL database connection failure errno: 1049 error
- Mysql error when deleting the table structure: Error Code: 1217. Cannot delete or update a parent row: a foreign key constraint fails
- 【Exception】mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table…
- mysql Table ‘performance_ schema.session_ Variables’ doesn’t exist solution
- An error was reported in the process of importing the table from mysql5.7: [err] 1067 – invalid default value for ‘***‘
- Global lock, table lock and row lock in MySQL
- An error occurred when opensips started the service“ ERROR:core :db_ check_ table_ Version: invalid version 7 for Table dialog found “
- Solutions to UCenter Info: MySQL query error app1
- Sorting out MySQL “too many connections” solutions
- 1093 – You can’t specify target table ‘table’ for update in FROM clause