title: mysql alter table FOREIGN KEY!
body: <p>(I using workbench) i have table <code>questions</code> with <code>id, user_id, text</code> and  table <code>users</code> with fields <code>id, name</code></p>
  
  <p>I need to relate this 2 tables!</p>
  
  <p>I write following:</p>
  
  <pre><code>ALTER TABLE `mydb_development`.`questions`
  ADD CONSTRAINT fk_QueUsers_1
  FOREIGN KEY (`user_id`)
  REFERENCES `mydb_development`.`users`(`id`);
  </code></pre>
  
  <p>but i get:</p>
  
  <pre><code>ERROR 1046: No database selected
  SQL Statement:
  ALTER TABLE  `questions` 
  ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`)
  
  ERROR: Error when running failback script. Details follow.
  
  ERROR 1046: No database selected
  SQL Statement:
  CREATE TABLE `questions` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `user_id` int(11) unsigned NOT NULL,
    `text` text NOT NULL,
    `security_token` varchar(40) NOT NULL,
    `created_at` datetime NOT NULL,
    `updated_at` datetime NOT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=373 DEFAULT CHARSET=utf8
  
  ERROR 1046: No database selected
  SQL Statement:
  ALTER TABLE  `questions` 
  ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`)
  
  ERROR: Error when running failback script. Details follow.
  
  .....................
  </code></pre>
  
  <p><strong>EDIT:</strong>
  I tried to do:</p>
  
  <pre><code>USE `mydb_development`;
  
  ALTER TABLE  `mydb_development`.`questions`
  
  ADD CONSTRAINT `fk_QueUsers_1`
  
  FOREIGN KEY (`user_id`)
  
  REFERENCES  `mydb_development`.`users`(`id`);
  </code></pre>
  
  <p>and i get error:</p>
  
  <pre><code>Error Code: 1005
  Can't create table 'survey_development.#sql-4ad_45' (errno: 150)
  </code></pre>
  
  <p>DOnt understand:S</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>my user table:</p>
  
  <pre><code>DROP TABLE IF EXISTS `mydb_development`.`users`;
  CREATE TABLE  `mydb_development`.`users` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `name` varchar(255) NOT NULL,
    `email` varchar(255) NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `email` (`email`)
  ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
  </code></pre>