Warning: count(): Parameter must be an array or an object that implements Countable in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 820

1 (edited by neworld 2010-04-20 22:51:16)

Topic: Nesukuria lenteles [innoDB]

Nesuprantu, kodėl meta klaidą 150 klaidą, ir nieko konkretesnio neparašo:

Bandau sukurti tokią lentelę:

CREATE TABLE `zones` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `x` INT  NOT NULL,
  `y` INT  NOT NULL,
  `pid` int(10) unsigned NOT NULL,
  `building` int UNSIGNED NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE `coo`(`x`, `y`),
  index `pid` (`pid`),
  INDEX `building`(`building`),
  CONSTRAINT `parkas` FOREIGN KEY `parkas` (`pid`)
    REFERENCES `parks` (`id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE
)
ENGINE = InnoDB;

Kurios referencas yra:

CREATE TABLE  `parks` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(32) NOT NULL,
  `user` int(10) unsigned NOT NULL,
  `x` int(10) unsigned NOT NULL,
  `y` int(11) NOT NULL,
  `money` bigint(20) unsigned NOT NULL,
  `point` int(10) unsigned NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `guest` int(10) unsigned NOT NULL DEFAULT '0',
  `guestLocal` int(10) unsigned NOT NULL DEFAULT '0',
  `guestRemote` int(10) unsigned NOT NULL DEFAULT '0',
  `lastHit` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `title` (`title`),
  UNIQUE KEY `cord` (`x`,`y`),
  KEY `user` (`user`),
  CONSTRAINT `new_fk_constraint` FOREIGN KEY (`user`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8

forumuose žmonės rašo, kad nesutampa foreign key ir referenco duomenų tipai. Ir dar skaičiau kažkur, kad tipo negalima sukurti lentelės, kurios referencinė lentelė jau turi kitą referencą.

Iš anksto ačiū.

Re: Nesukuria lenteles [innoDB]

Radau klaidą. Kadangi pas mane on delete yra set null, tačiau `pid` int(10) unsigned NOT NULL, negali būti null. čia ir buvo klaida. Gal kam nors pravers mano patirtis :)