【发布时间】:2013-12-04 15:08:29
【问题描述】:
我试图删除一个表并使用以下代码变体截断它。以下所有版本都给我同样的错误。
代码: puts "清除数据库表:program_slots" ProgramSlot.destroy_all ActiveRecord::Base.connection.execute("TRUNCATE TABLE program_slots")
puts "Clearing Database Table: program_slots"
ProgramSlot.destroy_all
ActiveRecord::Base.connection.execute("TRUNCATE TABLE PROGRAMSLOTS")
puts "Clearing Database Table: program_slots"
ProgramSlot.destroy_all
ActiveRecord::Base.connection.execute("TRUNCATE TABLE 'program_slots'")
puts "Clearing Database Table: program_slots"
ProgramSlot.destroy_all
ActiveRecord::Base.connection.execute("TRUNCATE TABLE PROGRAM_SLOTS")
表名是 program_slots
我得到的错误是:
>> ProgramSlot Load (0.6ms) SELECT `program_slots`.* FROM `program_slots`
(0.8ms) TRUNCATE TABLE PROGRAMSLOTS
Mysql2::Error: Table 'dd_development.programslots' doesn't exist: TRUNCATE TABLE PROGRAMSLOTS
什么是正确的语法?我在执行语句中的下划线似乎没有通过.......注意错误语句试图找到一个名为“programslots”的表,但真正的表名是“program_slots”。
我该如何解决这个问题?
【问题讨论】:
标签: ruby-on-rails activerecord ruby-on-rails-4 mysql2