I have a many-to-many table user_processes that consists of two columns: user and process. user is a foreign key referencing the user table’s primary key. The process column is a foreign key referencing the processes primary key. However, I don’t need a separate primary key column in user_processes since a multi-column primary key on user, process should be enough (right? I’m not seeing a need for a separate id column). One user can have many processes, but there shouldn’t be multiple rows with the same user having the same process.
The following code is giving me the error “#1005 – Can’t create table ‘test.user_processes’ (errno: 150) (Details…) ” in phpmyadmin.
Here’s the code, generated by mysql workbench:
-- -----------------------------------------------------
-- Table `test`.`user_processes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `test`.`user_processes` (
`user` INT UNSIGNED NOT NULL ,
`process` INT UNSIGNED NOT NULL ,
PRIMARY KEY (`user`, `process`) ,
INDEX `fk_user_processes_users1_idx` (`user` ASC) ,
INDEX `fk_user_processes_processes1_idx` (`process` ASC) ,
CONSTRAINT `fk_user_processes_users1`
FOREIGN KEY (`user` )
REFERENCES `test`.`users` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_user_processes_processes1`
FOREIGN KEY (`process` )
REFERENCES `test`.`processes` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
Any idea why it’s not letting me do this, and what the right solution is?
The table
usersand/orprocessesmight not exists. Make sure that the create table statements for the referenced tables are executed before calling this.Or the type of the referenced fields
users.idand/orprocesses.iddon’t match the type of the fieldsuser_processes.user/user_processes.process. In this case, those fields should also beINT UNSIGNED.