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 7646307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:10:26+00:00 2026-05-31T10:10:26+00:00

I have written some SQL code to create five tables with several relations(foreign keys).

  • 0

I have written some SQL code to create five tables with several relations(foreign keys).

The first foreign key relation works fine, the tables are created without any errors, but when I try to create gasten_url_toegangscodes I get the following error:

#1005 - Can't create table 'dbname.gasten_url_toegangscodes' (errno: 150).

I’ve read the docs about foreign keys and I still can’t find the problem.. The most strange thing about this is that it works in the first three tables..

Can anyone help me please?

My full SQL code is:

CREATE TABLE IF NOT EXISTS `groepen` (
  `id` tinyint(3) NOT NULL AUTO_INCREMENT,
  `naam` varchar(50) NOT NULL DEFAULT '',
  `status` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `gasten` (
  `id` int(5) NOT NULL AUTO_INCREMENT,
  `bedrijf` varchar(100) NOT NULL DEFAULT '',
  `uniek` varchar(64) NOT NULL,
  `groepid` tinyint(3) NOT NULL,
  PRIMARY KEY (`id`),
  FOREIGN KEY (groepid) REFERENCES `groepen` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `passen` (
  `id` tinyint(3) NOT NULL AUTO_INCREMENT,
  `naam` varchar(30) NOT NULL DEFAULT '',
  `color` varchar(7) NOT NULL DEFAULT '#FFFFFF',
  `bekend` tinyint(1) NOT NULL DEFAULT '0',
  `welkom` tinyint(1) NOT NULL DEFAULT '0',
  `aantal` tinyint(1) NOT NULL DEFAULT '0',
  `nummer` int(11) NOT NULL DEFAULT '0',
  `begrens` tinyint(1) NOT NULL DEFAULT '0',
  `status` tinyint(1) NOT NULL DEFAULT '1',
  `priority` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `naam` (`naam`)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `gasten_url_toegangscodes` (
  `uniek` varchar(64) NOT NULL,
  `unieke_url_code` char(64) NOT NULL,
  `salt` char(16) NOT NULL,
  FOREIGN KEY (uniek) REFERENCES `gasten` (`uniek`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `gasten_tickets` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `pas_id` tinyint(3) NOT NULL,
  `uniek` varchar(64) NOT NULL,
  `barcode` char(16) NOT NULL,
  `secret_key` char(32) NOT NULL,
  `download_count` int(11) NOT NULL DEFAULT '0',
  `last_download_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `scanned` enum('N','Y') NOT NULL,
  `scanned_datetime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`id`),
  FOREIGN KEY (uniek) REFERENCES `gasten` (`uniek`) ON DELETE CASCADE ON UPDATE NO ACTION,
  FOREIGN KEY (pas_id) REFERENCES `passen` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB;

Thanks in advance!

  • 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-31T10:10:28+00:00Added an answer on May 31, 2026 at 10:10 am

    Create an index on gasten.uniek

    CREATE TABLE IF NOT EXISTS `gasten` (
      `id` int(5) NOT NULL AUTO_INCREMENT,
      `bedrijf` varchar(100) NOT NULL DEFAULT '',
      `uniek` varchar(64) NOT NULL,
      `groepid` tinyint(3) NOT NULL,
      PRIMARY KEY (`id`),
      INDEX `idx_uniek` (`uniek`),
      FOREIGN KEY (groepid) REFERENCES `groepen` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
    ) ENGINE=InnoDB;
    

    And set the charset of the FK in gasten_url_toegangscodes the same as that of the related column in gasten.

    Assuming gasten is UTF-8:

    CREATE TABLE IF NOT EXISTS `gasten_url_toegangscodes` (
      /* use same charset for this column */
      `uniek` varchar(64) NOT NULL CHARSET UTF-8,
      `unieke_url_code` char(64) NOT NULL,
      `salt` char(16) NOT NULL,
      FOREIGN KEY (uniek) REFERENCES `gasten` (`uniek`) ON DELETE CASCADE ON UPDATE NO ACTION
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with some SQL 2005 CLR code written in C#. We have recently
Hi I have some software written in VB6.0 that uses an SQL Server, but
Hai Techies, I have some stored procedure which was written in SQL server.Now i
I have written some code in my VB.NET application to send an HTML e-mail
I have written some code for playing a .wav through my application. Now I
I have written some jQuery ajax code where I am sending a request to
I have written some code to ensure that items on an order are all
I have written some code to look at properties using reflection. I have retrieved
I have written a trivial Entities code-first WinForms application with one simple class and
I'm refactoring some code and I have written a method that modifies a Dictionary

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.