#1005 - Can't create table '.\test\pc.frm' (errno: 150)

Alles, was MariaDB und MySQL betrifft, kann hier besprochen werden.

#1005 - Can't create table '.\test\pc.frm' (errno: 150)

Postby Ngar » 04. November 2007 10:46

Hallo,

nachdem ich endlich die Referenz über Fremdschlüssel hin bekommen habe und meine eigentliche DB anlegen möchte, erhalte ich obige für mich nicht zu erschliessende Fehlermeldung.

Zuerst lege ich folgende 3 Tabellen an:
Code: Select all
CREATE TABLE area (
  area_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  area VARCHAR(20) NULL,
  PRIMARY KEY(area_id)
) engine=innoDB;

CREATE TABLE location (
  location_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  location VARCHAR(20) NULL,
  PRIMARY KEY(location_id)
) engine=innoDB;

CREATE TABLE organisation (
  organisation_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  organisation VARCHAR(20) NULL,
  PRIMARY KEY(organisation_id)
) engine=innoDB;


Anschliessend möchte ich eine Tabelle mit den Fremdschlüsseln aus den ersten 3 Tabellen erstellen.

Code: Select all
CREATE TABLE pc (
  pc_id INTEGER NOT NULL AUTO_INCREMENT,
  area_id INTEGER UNSIGNED NOT NULL,
  organisation_id INTEGER UNSIGNED NOT NULL,
  location_id INTEGER UNSIGNED NOT NULL,
  name VARCHAR(20) NOT NULL,
  mac_adress VARCHAR(12) NOT NULL,
  static_ip VARCHAR(15) NULL,
  date_purchase DATE NOT NULL,
  billnr_purchase VARCHAR(12) NOT NULL,
  PRIMARY KEY(pc_id),
  INDEX i_area_id( area_id ) ,
  INDEX i_ogranisation_id( organisation_id ) ,
  INDEX i_location_id( location_id ) ,
  FOREIGN KEY(location_id)
    REFERENCES location,
   FOREIGN KEY(organisation_id)
    REFERENCES organisation,
   FOREIGN KEY(area_id)
    REFERENCES area
) engine=innoDB;


an dieser Stelle erhalte ich dann obige Fehlermeldung.

Verwende ich folgende Syntax
Code: Select all
...
 FOREIGN KEY(location_id)
    REFERENCES location(location_id),
  FOREIGN KEY(organisation_id)
    REFERENCES organisation(organisation_id),
  FOREIGN KEY(area_id)
    REFERENCES area(area_id)
) engine=innoDB;


erhalte ich folgende Fehlermeldung
Code: Select all
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'area(area_id)
) ENGINE = innoDB' at line 18

Ich verstehe auch nicht, warum der Syntax-Fehler erst im Foreign Key für area auftritt und nicht schon früher.

Ich bin ziemlich ratlos :oops:

Wo ist mein Fehler?

Vielen Dank

Ngar
Ngar
 
Posts: 8
Joined: 02. November 2007 12:11

Postby Ngar » 04. November 2007 11:40

hmm,

ich habe jetzt einmal den Namen der Tabelle area zu areas geändert.

Nun kann ich die Tabelle erstellen.

Aber warum hat MySQL ein Problem mit dem Namen area?

Danke

Ngar
Ngar
 
Posts: 8
Joined: 02. November 2007 12:11

Postby glitzi85 » 04. November 2007 14:10

Hallo,

vermutlich weil's eine MySQL-Funktion ist: http://dev.mysql.com/doc/refman/5.0/en/multipolygon-property-functions.html

Immer schön deine Tabellen und Spalten mit ` maskieren, dann passiert sowas nicht. Also nicht
Code: Select all
SELECT irgendwas FROM irgendwo

sondern
Code: Select all
SELECT `irgendwas` FROM `irgendwo`


Wenn du dir das von vornherein angewöhnst, umgehst du solcher Fehler elegant. Ist mir am Anfang auch mit einer Umleitungstabelle passiert, in der ich die Felder mit from und to benannt hatte (wobei es eigentlich klar hätte sein müssen, dass from SQL-Syntax ist *übereigenedummheitwunder*).

mfg glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim


Return to MariaDB - MySQL

Who is online

Users browsing this forum: No registered users and 66 guests