Error 1064 Mysql 42000 Foreign Key
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn error 1064 mysql 42000 create database more about Stack Overflow the company Business Learn more about hiring developers or posting
Error 1064 Mysql 42000 Mysqldump
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community error 1064 mysql 42000 grant all Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up MySQL ERROR 1064 (42000) - even with backticks up vote error 1064 mysql 42000 insert 1 down vote favorite I must be missing something obvious, but still... I get MySQL ERROR 1064 (42000) when I try to run the following: CREATE TABLE `mgr_user` ( `id` INT NOT NULL AUTO_INCREMENT, `customer_id` INT NOT NULL, `username` VARCHAR(25), `password` VARCHAR(100), INDEX(`customer_id`), FOREIGN KEY `customer_id` REFERENCES `customer`(`id`) ON UPDATE CASCADE ON DELETE RESTRICT ); mysql foreign-keys share|improve this question asked Feb 8 '12 at 16:22 R.V. 2321216
Error 1064 Mysql 42000 You Have An Error In Your Sql Syntax
Show the full schema. –shiplu.mokadd.im Feb 8 '12 at 16:35 this is the only other create: –R.V. Feb 8 '12 at 16:48 CREATE TABLE customer ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(25), PRIMARY KEY(id) ); –R.V. Feb 8 '12 at 16:48 1 Please show the error message, which often helpfully reveals where the syntax error is. –pilcrow Feb 8 '12 at 16:53 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted You need to wrap around the foreign key name with parenthesis. Also your auto column must be a key. See bellow CREATE TABLE `mgr_user` ( `id` INT NOT NULL AUTO_INCREMENT, `customer_id` INT NOT NULL, `username` VARCHAR(25), `password` VARCHAR(100), INDEX(`customer_id`), UNIQUE KEY (`id`), -- <- Auto column is should be a key FOREIGN KEY (`customer_id`) REFERENCES `customer`(`id`) ON UPDATE CASCADE ON DELETE RESTRICT ); After these 2 changes, I got Query OK, 0 rows affected (0.07 sec) share|improve this answer answered Feb 8 '12 at 16:51 shiplu.mokadd.im 36.5k573142 Perfect! Thank you. –R.V. Feb 8 '12 at 16:57 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sig
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and error 1064 mysql 42000 create table policies of this site About Us Learn more about Stack Overflow the error 1064 mysql 42000 restore company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags
Error 1064 Mysql 42000 Mysql Import
Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only http://stackoverflow.com/questions/9197292/mysql-error-1064-42000-even-with-backticks takes a minute: Sign up MySQL CREATE TABLE & FOREIGN KEY Error up vote 3 down vote favorite 1 I'm not a DB guy, but I've been hacking away at this one for a bit and can't seem to nail the issue. I've read the relevant doc page (http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html) and I can't see where my syntax may be an issue. ERROR http://stackoverflow.com/questions/7912085/mysql-create-table-foreign-key-error 1064 (42000) at line 84: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE RESTRICT ON UPDATE C' at line 5 This is the relevant SQL - order(id) and user(id) are auto incrementing int(10) fields in their respective tables. DROP TABLE IF EXISTS `user_orders`; CREATE TABLE `user_orders` ( `user_id` int(10) unsigned NOT NULL default '0', `order_id` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`user_orders_user_id`, `user_orders_order_id`) FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE RESTRICT ON UPDATE CASCADE, FOREIGN KEY (order_id) REFERENCES order(id) ON DELETE RESTRICT ON UPDATE CASCADE, ) AUTO_INCREMENT=50; Help would be appreciated - especially if you can explain what I've missed. mysql mysql-error-1064 share|improve this question edited Oct 27 '11 at 5:44 mu is too short 284k41552558 asked Oct 27 '11 at 5:40 elithrar 9,58822752 add a comment| 2 Answers 2 active oldest votes up vote 5 down vote accepted You're missing a comma after your PK: PRIMARY KEY (`user_orders_user_id`, `user_orders_order_id`), -- <------- FOREIGN
DOMAINS WEB DESIGN WEB DESIGN SERVICES CREATE YOUR OWN WEBSITE SITE HOSTING TOOLS MEET US MEET US ABOUT US PARTNERS & AWARDS BLOG WE'RE http://www.inmotionhosting.com/support/website/database-troubleshooting/error-1064 HIRING CONTACT US AMP LOGIN SUPPORT CENTER Search Support Center Product Guides Dedicated Hosting Reseller Hosting KnowledgeBase Website Email Domain Names Reseller Billing Community Support Browse Questions Ask a Question User Submitted Articles Education Channels Android BoldGrid cPanel DokuWiki Drupal 7 Drupal 8 Everything Email Joomla 2.5 Joomla 3.1 K2 Magento 1.6 Mambo error 1064 MediaWiki Moodle Movable Type OpenCart OpenCart 2.0 osCommerce PHP-Fusion PHP-Nuke phpBB phpList Premium Website Builder PrestaShop 1.5 PrestaShop 1.6 SMF Tiki Wiki VirtueMart 3 Web Hosting Manager Website Design WordPress Tools & Resources Email Configuration Blacklist Check Visual DNS Lookup Quick Tagger Icon Sets Favicon Generator Bounce Back Parser What is my IP address? error 1064 mysql >>Website .htaccess (17)Adobe Flash (2)APIs (2)Backup and Restore (15)Billing (8)Browser Issues (2)Connecting to a Database (5)cPanel (26)cPanel Account Management (16)Cron Jobs (4)Cube Cart (2)Database Setup (5)Database Troubleshooting (6)Domain Management (2)Dreamweaver (12)Drush (2)eCommerce (7)Elasticsearch (4)Fantastico (4)File Management (16)File Manager (6)FTP (10)FTP Client Setup (21)General Server Setup / Management (15)Getting Started Guides (18)Ghost (3)Google Tools (21)How To (23)HTML (2)Image Editing (2)IP Addresses (3)iWeb (1)JavaScript (2)Joomla (10)Joomla 2.5 (36)Koken (11)Linux (27)Logaholic (5)Magento (2)Maintaining Your Website (1)Managing Files (7)Microsoft FrontPage (11)Microsoft Publisher (1)ModSecurity (7) MODx (3)New Customers (7)Open Classifieds (1)PCI Compliance (7)PHP (15)PHP Configuration (7)PHP Troubleshooting (6)phpBB (25)phpMyAdmin (10)Premium Website Builder (22)Prestashop (1)Protecting Files (5)Publishing Your Site (2)Python (1)Redirects (4)Restricting Bots (5)Search Engine Optimization (1)Secure Socket Layer (SSL) Tutorials (13)Security (12)Sending Email From Websites (2)Server Security (2)Server Usage (21)Slow Websites (7)Social Media (4)Software FAQs (11)Soho Web Builder (18)SSH and Root access (21)Statistics/Logging (12)Troubleshooting Comment Spam (3)Troubleshooting Hacked Websites (9)Web Host Manager (7)Website Error Numbers (4)Website Is Unavailable (3)Website Transfers (6)Website Troubleshooting (26)Welcome to