Schema file ruby on rails
NickName:Spencer Hire Ask DateTime:2014-07-15T16:19:26

Schema file ruby on rails

I've dropped my table successfully from the database from the console, using

ActiveRecord::Migration.drop_table(:foo),

But for some reason the table data still shows in the schema file.

I would like a method to do this without having to manually remove the data, (Doesn't give a proper rails feeling to it.)

Copyright Notice:Content Author:「Spencer Hire」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/24753199/schema-file-ruby-on-rails

Answers
Alvin S. Lee 2014-07-15T14:08:00

The schema file located in db/schema.rb was most likely generated the very last time you ran rake db:migrate. This is because rake db:migrate migrates your db through all of the migrations in your db/migrate folder, and then it calls the db:schema:dump task, which generates the schema file based on the current state of the database.\n\nFor your situation, after you have run ActiveRecord::Migration.drop_table(:foo) in the rails console, the current state of your database (now, no longer having the table foo) is not in sync with the schema.rb file that was generated when you last migrated.\n\nWhat you want to do at this point is re-dump the schema based on the current state of the database, and you do this by running rake db:schema:dump. This will take the current state of your database (without the table foo) and generate your db/schema.rb file.\n\nFor more information on the schema file and its relationship to migrations, I would recommend looking at the Rails Guide on Active Record Migrations: Schema Dumping and You.",


More about “Schema file ruby on rails” related questions

Using Postgres Schema with Ruby on Rails

I have a separate server that contains a Ruby on Rails API ( DB is postgres) that will used by multiple, different, applications. I was thinking of using schemas to sort the tables that each applic...

Show Detail

ruby on rails Models Schema

Hello every one I'm new to ruby on rails. I go through the following code in which I'm told that database schema is being loaded through this code: Account.current = Question.find(2) Question.last...

Show Detail

Ruby On Rails ActiveRecord SQL view into schema

I created a view and was able to successfully access it through rails by creating the view through a migration with execute sql. The problem with this is that the view is not entered into the sche...

Show Detail

Ruby Rails rake db migrate not working or schema file not updating

So I created a new table on schema.rb here is the new code line i put: create_table "book", :force => true do |t| t.integer "user_id" t.string "title" t.integer "count&q

Show Detail

Unwanted tables in schema file for rails app

While working on a ruby on rails group project, I found two tables in my schema.rb file that doesn't match with any of the migration history files. Is there a rake command to clean up the schema fi...

Show Detail

New to SQL / Ruby on Rails - database created, schema dumb error

I'm working on teaching myself both SQL & Ruby on Rails, and just starting out. I'm following a tutorial and successfully created a new SQL database and user, as well as a project. The next s...

Show Detail

Generating a JSON schema from a Ruby on rails model (class)

There are gems for generating json from Ruby instances (e.g., jbuilder) and gems for building Ruby models from json schemata. Is there one for doing the inverse? That is, for generating a json schema

Show Detail

Schema file ruby on rails

I've dropped my table successfully from the database from the console, using ActiveRecord::Migration.drop_table(:foo), But for some reason the table data still shows in the schema file. I would...

Show Detail

Ruby on Rails migrations run, schema.rb updated but changes not reflecting in psql database

I have a ruby on rails application already running in production. The database has records which I do not want to loose. I had to add and run new migrations to add some new columns to existing tabl...

Show Detail

Ruby on Rails deploy Capistrano sqlite db no schema

When trying to deploy Ruby on Rails application with Capistrano to Ubuntu 14 server, I've got an issue, the sqlite3 database file is always created, but no schema is loaded, the Capistrano deployment

Show Detail