Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MySQL Tables insert
After a long search on the internet i managed to write a database using a couple of examples, but yet i cannot run it propely, there are many errors that after tons of reading i cannot solve :/ I'm self learner, which makes it even more difficult to resolve, thanks to the community of The Code Project i managed to write quite a lot and i've learned pretty much, but yet some things that shall run well, are not. I'm posting the whole code, and i'm hoping for this last time regarding MySQL i can ask the very last question, well one, but a long one. Thing is that most of the code got accepted couple month ago and i got generated it from less structured by WorkBench while running it :/
 
MySQL didn't managed to create tables: dostawcy & kategoria
MySQL didn't managed to put data in table produkty
 
ERROR:
0   22:24:07    INSERT INTO `rowerowy`.`produkty` (`produkt_id`, `produkt_producent`, `produkt_model`, `produkt_rok`, `produkt_cena_kupna`, `produkt_cena`, `produkt_zarobek`, `produkt_ilosc`, `kategoria_id`, `dostawcy_id`)  VALUES  (`DEFAULT`,`Marzocchi`,`Bomber 66 ATA`,`2010`,`3999.00`,`4120`,`DEFAULT`,`2`,`4`,`2`),  (`DEFAULT`,`Marzocchi`,`Bomber 66 SL1`,`2012`,`2299`,`2657`,`DEFAULT`,`1`,`4`,`2`), (`DEFAULT`,`ROCK SHOX`,`Boxxer WC`,`2012`,`2432`,`5999.00`,`DEFAULT`,`1`,`3`,`2`), (`DEFAULT`,`AVID`,`Code`,`2012`,`865.23`,`999.00`,`DEFAULT`,`3`,`3`,`4`), (`DEFAULT`,`MANITOU`,`REVOX`,`2012`,`992.23`,`999.00`,`DEFAULT`,`2`,`4`,`2`), (`DEFAULT`,`NS Bikes`,`Crank solid`,`NULL`,`456`,`87`,`DEFAULT`,`2`,`2`,`8`), (`DEFAULT`,`NS Bikes`,`Leg Eaters czarne`,`NULL`,`123.43`,`180.00`,`DEFAULT`,`5`,`2`,`15`) Error Code: 1054. Unknown column 'DEFAULT' in 'field list'
 

 
I assume that it cannot put the data into kategoria, because it cannot create the table, so that's the only constrain to make the rest work.
 
ERROR ON table kategoria:
0   22:13:08    CREATE  TABLE `rowerowy`.`kategoria` (    `kategoria_id` INT NOT NULL AUTO_INCREMENT,    `kategoria` VARCHAR(45) NOT NULL ,    `produkt_id` INT NOT NULL,    PRIMARY KEY (`kategoria_id`),    CONSTRAINT `produkt_id`      FOREIGN KEY (`produkt_id`)      REFERENCES `rowerowy`.`produkty` (`produkt_id`)      ON DELETE NO ACTION      ON UPDATE NO ACTION )  Error Code: 1005. Can't create table 'rowerowy.kategoria' (errno: 121)
 
ERROR on table dostawcy:
1   22:24:07    DROP TABLE IF EXISTS `dostawcy` 0 row(s) affected, 1 warning(s): 1051 Unknown table 'dostawcy'
 
0   22:24:07    CREATE  TABLE `rowerowy`.`dostawcy` (    `dostawcy_id` INT NOT NULL AUTO_INCREMENT ,    `dostawcy_nazwa` VARCHAR(45) NOT NULL ,    `dostawcy_ulica` VARCHAR(45) NOT NULL ,    `dostawcy_numer_domu` INT(5) NOT NULL ,    `dostawcy_numer_mieszkania` INT(5) NULL ,    `dostawcy_kod_pocztowy` INT(5) NOT NULL ,    `dostawcy_miasto` VARCHAR(45) NOT NULL ,    `dostawcy_mail` VARCHAR(45) NOT NULL ,    `dostawcy_telefon` INT(9) NOT NULL ,    `produkt_id` INT NOT NULL,    PRIMARY KEY (`dostawcy_id`),    CONSTRAINT `produkt_id`      FOREIGN KEY (`produkt_id`)      REFERENCES `rowerowy`.`produkty` (`produkt_id`)      ON DELETE NO ACTION      ON UPDATE NO ACTION      ) ENGINE = InnoDB AUTO_INCREMENT = 66000 Error Code: 1005. Can't create table 'rowerowy.dostawcy' (errno: 121)
 

CREATE DATABASE /*!32312 IF NOT EXISTS*/`rowerowy` /*!40100 DEFAULT CHARACTER SET latin1 */;
 
USE `rowerowy`;
 
SET FOREIGN_KEY_CHECKS = 0;
 

DROP TABLE IF EXISTS `produkty`;
 
CREATE  TABLE `rowerowy`.`produkty` (
 
  `produkt_id` INT NOT NULL AUTO_INCREMENT ,
 
  `produkt_producent` VARCHAR(45) NOT NULL ,
 
  `produkt_model` VARCHAR(45) NOT NULL ,
 
  `produkt_rok` INT(4) NULL ,
 
  `produkt_cena_kupna` DECIMAL NULL ,
 
  `produkt_cena` DECIMAL NULL ,
 
  `produkt_zarobek` DECIMAL NULL ,
 
  `produkt_ilosc` INT(10) NULL ,
 
  `kategoria_id` INT NOT NULL ,
 
  `dostawcy_id` INT NOT NULL ,
 
  `koszyk_id` INT NOT NULL ,
 
  PRIMARY KEY (`produkt_id`) ,
 
  INDEX `koszyk_id` (`koszyk_id` ASC) ,
 
  INDEX `dostawcy_id` (`dostawcy_id` ASC) ,
 
  INDEX `kategoria_id` (`kategoria_id` ASC) ,
 
  CONSTRAINT `koszyk_id`
 
    FOREIGN KEY (`koszyk_id` )
 
    REFERENCES `rowerowy`.`koszyk` (`koszyk_id` )
 
    ON DELETE NO ACTION
 
    ON UPDATE NO ACTION,
 
  CONSTRAINT `dostawcy_id`
 
    FOREIGN KEY (`dostawcy_id` )
 
    REFERENCES `rowerowy`.`dostawcy` (`dostawcy_id` )
 
    ON DELETE NO ACTION
 
    ON UPDATE NO ACTION,
 
  CONSTRAINT `kategoria_id`
 
    FOREIGN KEY (`kategoria_id` )
 
    REFERENCES `rowerowy`.`kategoria` (`kategoria_id` )
 
    ON DELETE NO ACTION
 
    ON UPDATE NO ACTION
);
 

 
INSERT INTO `rowerowy`.`produkty` (`produkt_id`, `produkt_producent`, `produkt_model`, `produkt_rok`, `produkt_cena_kupna`, `produkt_cena`, `produkt_zarobek`, `produkt_ilosc`, `kategoria_id`, `dostawcy_id`) 
VALUES 
(`DEFAULT`,`Marzocchi`,`Bomber 66 ATA`,`2010`,`3999.00`,`4120`,`DEFAULT`,`2`,`4`,`2`), 
(`DEFAULT`,`Marzocchi`,`Bomber 66 SL1`,`2012`,`2299`,`2657`,`DEFAULT`,`1`,`4`,`2`),
 
 
DROP TABLE IF EXISTS `kategoria`;
 
  CREATE  TABLE `rowerowy`.`kategoria` (
 
  `kategoria_id` INT NOT NULL AUTO_INCREMENT,
 
  `kategoria` VARCHAR(45) NOT NULL ,
 
  `produkt_id` INT NOT NULL,
 
  PRIMARY KEY (`kategoria_id`),
 
  CONSTRAINT `produkt_id`
 
    FOREIGN KEY (`produkt_id`)
 
    REFERENCES `rowerowy`.`produkty` (`produkt_id`)
 
    ON DELETE NO ACTION
 
    ON UPDATE NO ACTION
);
 

INSERT INTO `rowerowy`.`kategoria` (`kategoria_id`, `kategoria`) VALUES (DEFAULT, `AKCESORIA`);
 
INSERT INTO `rowerowy`.`kategoria` (`kategoria_id`, `kategoria`) VALUES (DEFAULT, `AMORTYZATORY I DAMPERY`);
 
INSERT INTO `rowerowy`.`kategoria` (`kategoria_id`, `kategoria`) VALUES (DEFAULT, `DETKI`);
 

DROP TABLE IF EXISTS `dostawcy`;
 
CREATE  TABLE `rowerowy`.`dostawcy` (
 
  `dostawcy_id` INT NOT NULL AUTO_INCREMENT ,
 
  `dostawcy_nazwa` VARCHAR(45) NOT NULL ,
 
  `dostawcy_ulica` VARCHAR(45) NOT NULL ,
 
  `dostawcy_numer_domu` INT(5) NOT NULL ,
 
  `dostawcy_numer_mieszkania` INT(5) NULL ,
 
  `dostawcy_kod_pocztowy` INT(5) NOT NULL ,
 
  `dostawcy_miasto` VARCHAR(45) NOT NULL ,
 
  `dostawcy_mail` VARCHAR(45) NOT NULL ,
 
  `dostawcy_telefon` INT(9) NOT NULL ,
 
  `produkt_id` INT NOT NULL,
 
  PRIMARY KEY (`dostawcy_id`),
 
  CONSTRAINT `produkt_id`
 
    FOREIGN KEY (`produkt_id`)
 
    REFERENCES `rowerowy`.`produkty` (`produkt_id`)
 
    ON DELETE NO ACTION
 
    ON UPDATE NO ACTION
    
) ENGINE = InnoDB AUTO_INCREMENT = 66000;
 
INSERT INTO `rowerowy`.`dostawcy` (`dostawcy_id`,`dostawcy_nazwa`,`dostawcy_ulica`,`dostawcy_numer_domu`,`dostawcy_numer_mieszkania`, `dostawcy_kod_pocztowy`,`dostawcy_miasto`,`dostawcy_mail`,`dostawcy_telefon`, `dostawcy_telefon`)
VALUES
(`DEFAULT`,`SHIMANO`,`Warszawska`,`9`,`NULL`,`05-943`,`Poznan`,`shimano_dostawa@shimano.com.pl`,`435897876`),
(`DEFAULT`,`NsBikes`,`Garwolinska`,`234`,`NULL`,`03-234`,`Wroclaw`,`ns_bikes@ns_bikes.pl`,`435823476`),
 
 

Please excuse me that it's written in my native language, it just makes it more understandable for me Smile | :)
Posted 13-Sep-12 10:27am
Edited 13-Sep-12 11:41am
v6
Comments
Kenneth Haugland at 13-Sep-12 17:38pm
   
I wont say you lack code in your question, this is waaaaay to much... Strip it down to the question you have, or else I dont think you'll get an answer, or at least not a quick answer. You also have some formatting that makes it hard to read.
Member 9152265 at 13-Sep-12 17:41pm
   
done it, thank you :)

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It's usually best if you take things one error at a time.
 
The first error you get is the table creation fails with a 121 error code.
 
If you google "mySQL 121 error" you'll find it's a "foreign key constraint error"
 
So, most likely there is a problem with:
 
CONSTRAINT `produkt_id`      FOREIGN KEY (`produkt_id`)
 
That same google will turn up this Q/A on stack overflow:
http://stackoverflow.com/questions/1180660/mysql-errorno-121[^]
 
The solution to the problem there turns out to be:
 
Quote:
Check that all your constraints are really spelled out correctly, also check that there's not any other tables that uses the constraint names...

 
Without knowing anything else about mySQL, it seems that constraint names need to be unique, so try changing the line to:
 
CONSTRAINT `produkt_id_constraint`      FOREIGN KEY (`produkt_id`)
 
or something similar. Also, review your documentation on creating foreign key constraint and make sure the rest is valid.
  Permalink  
Comments
Kenneth Haugland at 13-Sep-12 18:00pm
   
"It's usually best if you take things one error at a time." Amen to that :)
Member 9152265 at 13-Sep-12 19:08pm
   
Amen :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 359
1 Richard MacCutchan 320
2 OriginalGriff 240
3 Jared Sanow 145
4 Snehasish_Nandy 115
0 Sergey Alexandrovich Kryukov 5,969
1 OriginalGriff 5,005
2 CPallini 2,473
3 Richard MacCutchan 1,547
4 Abhinav S 1,507


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 15 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100