我是 ruby-on-rails 的新手并且很难过。
我尝试运行“rake db:migrate”,但由于输入错误而中止。我输入了“用户”而不是“用户”。所以我修复了 db/migrate 目录中的 rb 文件并尝试再次运行它,却发现迁移已经部分进行,我无法重做一遍。这似乎是像我这样的初学者的常见错误,讲师为此提出了两个解决方案:首先在 SQL 中删除表或第二个注释掉已经运行的部分并运行剩余部分。
但在我找到故障排除建议之前,我想我可以使用不同的文件名(SIGH),我将“用户”更改为“admin_user”,将“admin_user”更改为“admin_user2”。我没有工作,我放下桌子做了
$ rails 生成迁移 AlterUsers 和 $ rake db:migrate
但它再次中止,因为它找不到这个文件:users.frm。(我不知道 .frm 文件在哪里..)
非常感谢。
- - - - - - - - - - - - - -错误信息 - - - - - - - - - - - ------------------
$ rake db:migrate
== AlterUsers: migrating =====================================================
-- rename_table("users", "admin_users")
rake aborted!
An error has occurred, all later migrations canceled:
Mysql2::Error: Can't find file: './simple_cms_development/users.frm' (errno: 2 - No such file or directory): RENAME TABLE `users` TO `admin_users`/Users/gymmilo/Sites/simple_cms/db/migrate/20130927112013_alter_users.rb:3:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
---------------------------迁移文件---------- ------------------
class AlterUsers < ActiveRecord::Migration
def change
rename_table("users", "admin_users")
add_column("admin_users", "username", :string, :limit => 25)
change_column("admin_users", "email", :string, :limit => 100)
rename_column("admin_users", "password", "hashed_password")
add_column("admin_users", "salt", :string, :limit => 40)
puts "*** About to add an index ***"
add_index("admin_users", "username")
end
end
------------------------------(我已经把桌子掉了一次,结果是这样的!谢谢你的帮助。-- ------
mysql> SHOW TABLES;
+----------------------------------+
| Tables_in_simple_cms_development |
+----------------------------------+
| admin_users1 |
| schema_migrations |
+----------------------------------+
2 rows in set (0.00 sec)
mysql> DROP TABLE admin_users1;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
$ rake db:migrate
== AlterUsers: migrating =====================================================
-- rename_table("users", "admin_users")
rake aborted!
An error has occurred, all later migrations canceled:
Mysql2::Error: Can't find file: './simple_cms_development/users.frm' (errno: 2 - No such file or directory): RENAME TABLE `users` TO `admin_users`/Users/gymmilo/Sites/simple_cms/db/migrate/20130927112013_alter_users.rb:3:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
$ mysql -u simple_cms -p simple_cms_development
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 43
Server version: 5.6.13 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW TABLES;
+----------------------------------+
| Tables_in_simple_cms_development |
+----------------------------------+
| schema_migrations |
+----------------------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
$ pwd
/Users/gymmilo/Sites/simple_cms
$ rake db:migrate
== AlterUsers: migrating =====================================================
-- rename_table("users", "admin_users")
rake aborted!
An error has occurred, all later migrations canceled:
Mysql2::Error: Can't find file: './simple_cms_development/users.frm' (errno: 2 - No such file or directory): RENAME TABLE `users` TO `admin_users`/Users/gymmilo/Sites/simple_cms/db/migrate/20130927112013_alter_users.rb:3:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)