Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 710785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:39:41+00:00 2026-05-14T04:39:41+00:00

I created some tables using MySQL Workbench, and then did forward ‘forward engineer’ to

  • 0

I created some tables using MySQL Workbench, and then did forward ‘forward engineer’ to create scripts to create these tables. BUT, the scripts lead me to a number of problems. One of which involves the foreign keys. So I tried creating separate foreign key additions using alter table and I am still getting problems. The code is below (the set statements, drop/create statements I left in … though I don’t think they should matter for this):

 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

 DROP SCHEMA IF EXISTS `mydb` ;
 CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;

 -- -----------------------------------------------------
 -- Table `mydb`.`User`
 -- -----------------------------------------------------
 DROP TABLE IF EXISTS `mydb`.`User` ;

 CREATE  TABLE IF NOT EXISTS `mydb`.`User` (
   `UserName` VARCHAR(35) NOT NULL ,
   `Num_Accts` INT NOT NULL ,
   `Password` VARCHAR(45) NULL ,
   `Email` VARCHAR(45) NULL ,
   `User_ID` INT NOT NULL AUTO_INCREMENT ,
   PRIMARY KEY (`User_ID`) )
 ENGINE = InnoDB;


 -- -----------------------------------------------------
 -- Table `mydb`.`User_Space`
 -- -----------------------------------------------------
 DROP TABLE IF EXISTS `mydb`.`User_Space` ;

 CREATE  TABLE IF NOT EXISTS `mydb`.`User_Space` (
   `User_UserName` VARCHAR(35) NOT NULL ,
   `User_Space_ID` INT NOT NULL AUTO_INCREMENT ,
   PRIMARY KEY (`User_Space_ID`),
 FOREIGN KEY (`User_UserName`)
 REFERENCES `mydb`.`User` (`UserName`)
 ON UPDATE CASCADE ON DELETE CASCADE)
 ENGINE = InnoDB;

 SET SQL_MODE=@OLD_SQL_MODE;
 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

The error this produces is:
Error Code: 1005 Can’t create table ‘mydb.user_space’ (errno: 150)

Anybody know what the heck I’m doing wrong?? And anybody else have problems with the script generation done by mysql workbench? It’s a nice tool, but annoying that it pumps out scripts that don’t work for me.

[As an fyi here’s the script it auto-generates:

 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

 DROP SCHEMA IF EXISTS `mydb` ;
 CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;

 -- -----------------------------------------------------
 -- Table `mydb`.`User`
 -- -----------------------------------------------------
 DROP TABLE IF EXISTS `mydb`.`User` ;

 CREATE  TABLE IF NOT EXISTS `mydb`.`User` (
   `UserName` VARCHAR(35) NOT NULL ,
   `Num_Accts` INT NOT NULL ,
   `Password` VARCHAR(45) NULL ,
   `Email` VARCHAR(45) NULL ,
   `User_ID` INT NOT NULL AUTO_INCREMENT ,
   PRIMARY KEY (`User_ID`) )
 ENGINE = InnoDB;


 -- -----------------------------------------------------
 -- Table `mydb`.`User_Space`
 -- -----------------------------------------------------
 DROP TABLE IF EXISTS `mydb`.`User_Space` ;

 CREATE  TABLE IF NOT EXISTS `mydb`.`User_Space` (
   `User_Space_ID` INT NOT NULL AUTO_INCREMENT ,
   PRIMARY KEY (`User_Space_ID`) ,
   INDEX `User_ID` () ,
   CONSTRAINT `User_ID`
     FOREIGN KEY ()
     REFERENCES `mydb`.`User` ()
     ON DELETE NO ACTION
     ON UPDATE NO ACTION)
 ENGINE = InnoDB;


 SET SQL_MODE=@OLD_SQL_MODE;
 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

**
Thanks!]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:39:41+00:00Added an answer on May 14, 2026 at 4:39 am

    I haven’t used MySQL Workbench to generate a lot of schemas, but I found the problem in the script. The foreign key definition in the User_Space table is attempting to create a foreign key on an unindexed column in the User table. If you alter the User definition to have an index on UserName, like this:

      CREATE  TABLE IF NOT EXISTS `mydb`.`User` (
       `UserName` VARCHAR(35) NOT NULL ,
       `Num_Accts` INT NOT NULL ,
       `Password` VARCHAR(45) NULL ,
       `Email` VARCHAR(45) NULL ,
       `User_ID` INT NOT NULL AUTO_INCREMENT ,
       PRIMARY KEY (`User_ID`),
       INDEX(`UserName`)
     )
     ENGINE = InnoDB;
    

    … the script will succeed. It sounds like MySQL Workbench probably isn’t taking indexes into account when it generates the foreign key definitions. I’m not sure if you can fix this in your schema diagrams or if it’s a bigger bug in the program, but I’d see if you could add index definitions in the right places and determine if that fixes the script generation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a table in Microsoft Sql CE that I'm using to hold some
I'm using System.Data.OracleClient.OracleCommand to create a table and fill it out with some data.
I basically created some tables to play around with: I have Two main tables,
I have created some rounded navigation tabs using CSS and am having trouble when
I need to create an SQL query to insert some data into a table
Data table structure is: id1,id2,id3,id4,... (some other fields). I want to create summary query
I'm creating a bunch of migrations, some of which are standard create table or
I have created some extra functionality on my Linq-to-SQL classes to make things easier
I've created some fairly simple XAML, and it works perfectly (at least in KAXML).
I've created some MbUnit Test Fixtures that have SetUp methods marked with the SetUp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.