Skip to content

Instantly share code, notes, and snippets.

@khanh96le
Created April 27, 2018 02:39
Show Gist options
  • Save khanh96le/d8e3e661485c7704f210d175aebd2f2a to your computer and use it in GitHub Desktop.
Save khanh96le/d8e3e661485c7704f210d175aebd2f2a to your computer and use it in GitHub Desktop.
sqlalchemy.exc.IntegrityError: (_mysql_exceptions.IntegrityError) (1215, 'Cannot add foreign key constraint') [SQL: u'\nCREATE TABLE asker (\n\tcreated DATETIME NOT NULL, \n\tupdated DATETIME NOT NULL, \n\tid INTEGER NOT NULL AUTO_INCREMENT, \n\temail VARCHAR(64) NOT NULL, \n\tfacebook_id VARCHAR(20), \n\tmicrosoft_id VARCHAR(50), \n\tpassword_hash VARCHAR(64), \n\tpassword_salt VARCHAR(16), \n\taccess_token_nonce VARCHAR(8) NOT NULL, \n\tnickname VARCHAR(32), \n\tgrade_id INTEGER, \n\tfree_credit_balance INTEGER NOT NULL, \n\tpaid_credit_balance INTEGER NOT NULL, \n\tpromotional_session_balance INTEGER NOT NULL, \n\tpurchased BOOL NOT NULL, \n\tcurrent_problem_id INTEGER, \n\tavatar VARCHAR(255), \n\tstatus INTEGER NOT NULL, \n\tphone VARCHAR(32), \n\tweighted_rank FLOAT NOT NULL, \n\tweighted_bid FLOAT NOT NULL, \n\tphone_verified BOOL NOT NULL, \n\tsource VARCHAR(255), \n\tip_address VARCHAR(100), \n\tbrowser_fingerprint VARCHAR(255), \n\tfullname VARCHAR(50), \n\tgoogle_id VARCHAR(50), \n\tpayment_methods TEXT, \n\ttag VARCHAR(20), \n\tCONSTRAINT pk_asker PRIMARY KEY (id), \n\tCONSTRAINT fk_asker_current_problem_id_problem FOREIGN KEY(current_problem_id) REFERENCES problem (id), \n\tCONSTRAINT uq_asker_email UNIQUE (email), \n\tCONSTRAINT uq_asker_facebook_id UNIQUE (facebook_id), \n\tCONSTRAINT uq_asker_microsoft_id UNIQUE (microsoft_id)\n)\n\n']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment