MySQL said : #1005 Can't create table 'gennet','ops' (errno: 150 "Foreign key constraint is incorrectly formed)

by Newbie123   Last Updated July 11, 2019 17:24 PM - source

I am attempting to import a .sql file. The file has been entirely imported apart from this last piece of code which allows users to gain access to the website.

I have tried manually creating the tables with such users, but was unsuccessful. I have searched everywhere I could but no answers relate to me problem.

DROP TABLE IF EXISTS ops; CREATE TABLE ops ( id int(11) NOT NULL AUTO_INCREMENT, user_id int(11) NOT NULL, title varchar(255) NOT NULL, text longtext NOT NULL, image varchar(50) NOT NULL, location varchar(255) NOT NULL, start_date varchar(20) NOT NULL, end_date varchar(20) NOT NULL, slug varchar(255) NOT NULL, datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY user_id (user_id), CONSTRAINT ops_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS users; CREATE TABLE users ( id int(11) NOT NULL AUTO_INCREMENT, firstname varchar(70) NOT NULL, lastname varchar(70) NOT NULL, email varchar(70) NOT NULL, password varchar(50) NOT NULL, phone varchar(30) NOT NULL, publication_name varchar(255) NOT NULL, media_type varchar(70) NOT NULL, published_country varchar(70) NOT NULL, age_range varchar(50) NOT NULL, hobbies varchar(70) NOT NULL, website varchar(255) NOT NULL, company varchar(70) NOT NULL, about text NOT NULL, image varchar(50) NOT NULL, type int(11) NOT NULL, demographic_cis_male varchar(10) NOT NULL DEFAULT '0', demographic_cis_female varchar(10) NOT NULL DEFAULT '0', demographic_non_binary varchar(10) NOT NULL DEFAULT '0', demographic_transgender_male varchar(10) NOT NULL DEFAULT '0', demographic_transgender_female varchar(10) NOT NULL DEFAULT '0', demographic_lesbian varchar(10) NOT NULL DEFAULT '0', demographic_gay varchar(10) NOT NULL DEFAULT '0', demographic_bisexual varchar(10) NOT NULL DEFAULT '0', demographic_transgender varchar(10) NOT NULL DEFAULT '0', demographic_bame varchar(10) NOT NULL DEFAULT '0', ar_16_24 varchar(10) NOT NULL DEFAULT '0', ar_25_34 varchar(10) NOT NULL DEFAULT '0', ar_35_44 varchar(10) NOT NULL DEFAULT '0', ar_45_54 varchar(10) NOT NULL DEFAULT '0', ar_55_64 varchar(10) NOT NULL DEFAULT '0', ar_65_plus varchar(10) NOT NULL DEFAULT '0', print_readership varchar(50) NOT NULL DEFAULT '0', news_letter_readership varchar(50) NOT NULL DEFAULT '0', readership_income_currency varchar(100) NOT NULL DEFAULT '0', readership_income_percentage varchar(50) NOT NULL DEFAULT '0', social_demographic1_name varchar(50) NOT NULL, social_demographic1_value varchar(50) NOT NULL DEFAULT '0', social_demographic2_name varchar(50) NOT NULL, social_demographic2_value varchar(50) NOT NULL DEFAULT '0', social_demographic3_name varchar(50) NOT NULL, social_demographic3_value varchar(50) NOT NULL DEFAULT '0', social_demographic4_name varchar(50) NOT NULL, social_demographic4_value varchar(50) NOT NULL DEFAULT '0', social_demographic5_name varchar(50) NOT NULL, social_demographic5_value varchar(50) NOT NULL DEFAULT '0', online_unique_visitors varchar(50) NOT NULL DEFAULT '0', facebook_following varchar(50) NOT NULL DEFAULT '0', twitter_following varchar(50) NOT NULL DEFAULT '0', instagram_following varchar(50) NOT NULL DEFAULT '0', youtube_following varchar(50) NOT NULL DEFAULT '0', snapchat_following varchar(50) NOT NULL DEFAULT '0', pintrest_following varchar(50) NOT NULL DEFAULT '0', tumblr_following varchar(50) NOT NULL DEFAULT '0', country1_name varchar(50) NOT NULL, country1_percentage varchar(50) NOT NULL DEFAULT '0', country2_name varchar(50) NOT NULL, country2_percentage varchar(50) NOT NULL DEFAULT '0', country3_name varchar(50) NOT NULL, country3_percentage varchar(50) NOT NULL DEFAULT '0', country4_name varchar(50) NOT NULL, country4_percentage varchar(50) NOT NULL DEFAULT '0', country5_name varchar(50) NOT NULL, country5_percentage varchar(50) NOT NULL DEFAULT '0', publication_published varchar(50) NOT NULL DEFAULT '0', hobby_holidays varchar(50) NOT NULL DEFAULT '0', hobby_travel varchar(50) NOT NULL DEFAULT '0', hobby_grooming varchar(50) NOT NULL DEFAULT '0', hobby_beauty varchar(50) NOT NULL DEFAULT '0', hobby_fashion varchar(50) NOT NULL DEFAULT '0', hobby_shopping varchar(50) NOT NULL DEFAULT '0', hobby_home_interior varchar(50) NOT NULL DEFAULT '0', hobby_dining varchar(50) NOT NULL DEFAULT '0', hobby_fitness varchar(50) NOT NULL DEFAULT '0', hobby_socialising varchar(50) NOT NULL DEFAULT '0', hobby_music varchar(50) NOT NULL DEFAULT '0', hobby_tv_radio varchar(50) NOT NULL DEFAULT '0', hobby1_name varchar(50) NOT NULL, hobby1_percent varchar(50) NOT NULL DEFAULT '0', hobby2_name varchar(50) NOT NULL, hobby2_percent varchar(50) NOT NULL DEFAULT '0', hobby3_name varchar(50) NOT NULL, hobby3_percent varchar(50) NOT NULL DEFAULT '0', time_0600_1159 varchar(50) NOT NULL DEFAULT '0', time_1200_1559 varchar(50) NOT NULL DEFAULT '0', time_1600_1759 varchar(50) NOT NULL DEFAULT '0', time_1800_2159 varchar(50) NOT NULL DEFAULT '0', time_2200_0559 varchar(50) NOT NULL DEFAULT '0', time_others varchar(50) NOT NULL DEFAULT '0', listeners varchar(50) NOT NULL DEFAULT '0', listeners_income_currency varchar(50) NOT NULL DEFAULT '0', listeners_income_percentage varchar(50) NOT NULL DEFAULT '0', viewership varchar(50) NOT NULL DEFAULT '0', viewership_income_currency varchar(50) NOT NULL DEFAULT '0', viewership_income_percentage varchar(50) NOT NULL DEFAULT '0', ban int(1) NOT NULL DEFAULT '0', datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY type (type), CONSTRAINT users_ibfk_1 FOREIGN KEY (type) REFERENCES users_types (id) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS users_types; CREATE TABLE users_types ( id int(11) NOT NULL AUTO_INCREMENT, type varchar(50) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

The code should allow users to be able to log in/out of the website, or at the very least I should be able to.



Related Questions




When is the new design coming to Ask Ubuntu

Updated June 21, 2018 09:24 AM

What’s the redesigning campaign – in a nutshell?

Updated September 03, 2018 08:24 AM

Responsive Web Design - Media Queries

Updated October 31, 2018 19:24 PM