我无法从 ActiveRecord 的缓存中删除有关表和列的信息。我正在为没有 Rails 的 Ruby 使用 ActiveRecord。
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:database => #
:password => #
)
class Person < ActiveRecord::Base
belongs_to :peoples
end
enter code here
class Persons < ActiveRecord::Base
belongs_to :peoples
end
class People < ActiveRecord::Base
has_many :persons
end
Person.new
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'vkusno.people' doesn't exist: SHOW FULL FIELDS FROM `people`'
Persons.new
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'vkusno.persons' doesn't exist: SHOW FULL FIELDS FROM `persons`'
但我尝试连接到没有一些表和列的数据库。
在我在数据库中有一个表之前,“人,人,人,人”,但我删除了所有表并重新启动了我的服务器几次。
如果我将数据库更改为 sqlite,我会得到一些不存在的表,我正在处理这些表并删除这些表。
我该如何修复它?
UPD
ActiveRecord::Base.logger = Logger.new(STDOUT)
class AddFirst < ActiveRecord::Migration
def up
create_table :persons do |t|
t.integer :idd
t.string :name
t.string :href
t.string :sex
t.string :country
t.string :city
t.boolean :can_message
t.boolean :can_wall
t.string :photo
t.boolean :is_friend
t.boolean :is_client
end
create_table :people do |x|
x.integer :id_general
x.string :description
end
end
def down
drop_table :persons
drop_table :people
end
def keys
add_column :persons, :peoples_id, :integer
add_index :persons, :peoples_id
end
end
> AddFirst.new.up
-- create_table(:persons)
CREATE TABLE `persons` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `idd` int(11), `name` varchar(255), `href` varchar(255), `sex` varchar(255), `country` varchar(255), `city` varchar(255), `can_message` tinyint(1), `can_wall` tinyint(1), `photo` varchar(255), `is_friend` tinyint(1), `is_client` tinyint(1)) ENGINE=InnoDB
-- create_table(:people)
CREATE TABLE `people` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `id_general` int(11), `description` varchar(255)) ENGINE=InnoDB
=> {}
AddFirst.new.keys
-- add_column(:persons, :peoples_id, :integer)
ALTER TABLE `persons` ADD `peoples_id` int(11)
-- add_index(:persons, :peoples_id)
CREATE INDEX `index_persons_on_peoples_id` ON `persons` (`peoples_id`)
=> nil
> Person.new
=> #<Person id: nil, id_general: nil, description: nil>
> Persons.new
=> #<Persons id: nil, idd: nil, name: nil, href: nil, sex: nil, country: nil, city: nil, can_message: nil, can_wall: nil, photo: nil, is_friend: nil, is_client: nil>
> People.new
=> #<People id: nil, id_general: nil, description: nil>