0
我的代碼是:MySQL的活動記錄問題寫入新創建的表
# require gems
require 'rubygems'
require 'active_record'
# Start connetion to the server
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:user => "root",
:password => "password",
:database => "data"
)
# Create the table
ActiveRecord::Schema.define do
create_table :datatable do |table|
table.column :date, :string
table.column :word, :string
table.column :website, :string
end
end
class Table < ActiveRecord::Base; end
Table.create(:date => datenow, :word => someword, :website => mywebsite)
puts "code completed"
而當代碼要寫表說我得到一個錯誤:如果我創建一個
path/to/mysql_adapter.rb:287:in 'query': Table 'test.tables' doesn't exist (Mysql::Error)
在數據庫(數據)中稱爲表的表,然後我所有的數據都放到那裏。我想將它寫入我剛剛創建的表(數據表)。我怎樣才能解決這個錯誤?
如果我想讓'datatable'變量,我無法確定使用什麼語法。所以如果我之前說過datatable =「data」,那麼我需要在這裏放置什麼來選擇名爲「data」的表。謝謝。 – Benjamin
'datatable =「data」'使'datatable'成爲一個包含String,''data「'的變量。這聽起來像是一個完全不同的問題,但我恐怕現在我不明白你在問什麼。 –