0

I might be missing something here, I have given up after 2 weeks of trying, Can anyone maybe see something blindingly obvious why this will not import please ?

I have tried to check everything that I can think of but when I try to insert it I just get the 150 error message.

SET NAMES utf8;
SET time_zone = '+00:00';
SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';

DROP TABLE IF EXISTS `classifieds_announcements`;
CREATE TABLE `classifieds_announcements` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `author` int(11) NOT NULL,
  `category` int(11) NOT NULL,
  `title` tinytext NOT NULL,
  `text` text NOT NULL,
  `date` int(11) NOT NULL COMMENT 'timestamp',
  `expire` int(11) NOT NULL COMMENT 'timestamp',
  `photo` varchar(255) NOT NULL,
  `approved` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `author` (`author`),
  KEY `category` (`category`),
  CONSTRAINT `classifieds_announcements_ibfk_1` FOREIGN KEY (`author`) REFERENCES `users` (`idu`) ON DELETE CASCADE,
  CONSTRAINT `classifieds_announcements_ibfk_2` FOREIGN KEY (`category`) REFERENCES `classifieds_categories` (`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


DROP TABLE IF EXISTS `classifieds_categories`;
CREATE TABLE `classifieds_categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` tinytext NOT NULL,
  `parent` int(11) DEFAULT NULL,
  `allow_posting` int(11) DEFAULT '1' COMMENT 'may be 0 or 1 only if parent=0, else will be 1',
  `order` int(11) DEFAULT '50',
  PRIMARY KEY (`id`),
  KEY `parent` (`parent`),
  CONSTRAINT `classifieds_categories_ibfk_1` FOREIGN KEY (`parent`) REFERENCES `classifieds_categories` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


DROP TABLE IF EXISTS `classifieds_config`;
CREATE TABLE `classifieds_config` (
  `key` varchar(255) NOT NULL,
  `value` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `classifieds_config` (`key`, `value`) VALUES
('allow_emoticons', '1'),
('post_on_user_wall',   '1'),
('approve_new_posts',   '1'),
('index_columns',   '4'),
('time_between_announces',  '300'),
('time_between_reviews',    '90');

DROP TABLE IF EXISTS `classifieds_inputs`;
CREATE TABLE `classifieds_inputs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category` int(11) NOT NULL,
  `name` text NOT NULL,
  `type` varchar(255) NOT NULL,
  `options` text,
  `required` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `category` (`category`),
  CONSTRAINT `classifieds_inputs_ibfk_1` FOREIGN KEY (`category`) REFERENCES `classifieds_categories` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


DROP TABLE IF EXISTS `classifieds_inputs_answers`;
CREATE TABLE `classifieds_inputs_answers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `input` int(11) NOT NULL,
  `announce` int(11) NOT NULL,
  `answer` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `input` (`input`),
  KEY `announce` (`announce`),
  CONSTRAINT `classifieds_inputs_answers_ibfk_1` FOREIGN KEY (`input`) REFERENCES `classifieds_inputs` (`id`) ON DELETE CASCADE,
  CONSTRAINT `classifieds_inputs_answers_ibfk_2` FOREIGN KEY (`input`) REFERENCES `classifieds_inputs` (`id`) ON DELETE CASCADE,
  CONSTRAINT `classifieds_inputs_answers_ibfk_3` FOREIGN KEY (`announce`) REFERENCES `classifieds_announcements` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


DROP TABLE IF EXISTS `classifieds_reports`;
CREATE TABLE `classifieds_reports` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `reported_by` int(11) NOT NULL,
  `reported_announce` int(11) NOT NULL,
  `read` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `reported_by` (`reported_by`),
  KEY `reported_announce` (`reported_announce`),
  CONSTRAINT `classifieds_reports_ibfk_1` FOREIGN KEY (`reported_by`) REFERENCES `users` (`idu`) ON DELETE CASCADE,
  CONSTRAINT `classifieds_reports_ibfk_2` FOREIGN KEY (`reported_announce`) REFERENCES `classifieds_announcements` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


DROP TABLE IF EXISTS `classifieds_reviews`;
CREATE TABLE `classifieds_reviews` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `announce` int(11) NOT NULL,
  `score` tinyint(4) NOT NULL,
  `user` int(11) NOT NULL,
  `text` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `announce` (`announce`),
  KEY `user` (`user`),
  CONSTRAINT `classifieds_reviews_ibfk_1` FOREIGN KEY (`announce`) REFERENCES `classifieds_announcements` (`id`) ON DELETE CASCADE,
  CONSTRAINT `classifieds_reviews_ibfk_2` FOREIGN KEY (`user`) REFERENCES `users` (`idu`) ON DELETE CASCADE,
  CONSTRAINT `classifieds_reviews_ibfk_3` FOREIGN KEY (`announce`) REFERENCES `classifieds_announcements` (`id`) ON DELETE CASCADE,
  CONSTRAINT `classifieds_reviews_ibfk_4` FOREIGN KEY (`user`) REFERENCES `users` (`idu`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Jon Ward
  • 23
  • 3
  • Check your foreign keys and in which order you create/drop table: https://stackoverflow.com/questions/4061293/mysql-cant-create-table-errno-150 – RaphaMex Jun 13 '17 at 13:55
  • One thing that can make things easier is to create your tables as step 1 (no foreign keys) and then add the foreign keys after all the tables are created. This stop a lot of the problems with creation order. – Nigel Ren Jun 13 '17 at 13:59
  • Perfect, Thanks, That led me to tun off Enable foreign key checks and it inserted. Thanks So Much – Jon Ward Jun 13 '17 at 14:01
  • Complain to the vendor of whatever you're using to load this file -- there's a statement right here that should have disabled foreign key checks. `SET foreign_key_checks = 0;` – Michael - sqlbot Jun 14 '17 at 03:12

0 Answers0