In heroku I ran rake db:migrate and got the following error
== AlterBodyForDocuments: migrating ==========================================
-- change_column(:documents, :body, :mediumtext)
rake aborted!
An error has occurred, this and all later migrations canceled:
PGError: ERROR: type "mediumtext" does not exist
: ALTER TABLE "documents" ALTER COLUMN "body" TYPE mediumtext
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
this is my AlterBodyForDocuments migration:
class AlterBodyForDocuments < ActiveRecord::Migration
def change
change_column :documents, :body, :mediumtext
end
end
I think mediumtext is a mysql thing
heroku uses postgresql
use :text instead
Related
I am having trouble running any rake task for my Rails application, and no matter what task I run (rake db:migrate, rake db:reset, etc), I get the following error:
rake aborted!
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: pages: SELECT "pages".* FROM "pages"
I continue getting this error - no matter what rake task I run, and also when I try to run the server:
rails s
gets the following error
Exiting
/Users/terencedevine/.rvm/gems/ruby-2.1.2/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `initialize': SQLite3::SQLException: no such table: pages: SELECT "pages".* FROM "pages" (ActiveRecord::StatementInvalid)
Everything I find online suggests using rake db:reset but that returns the same error.
One of my more recent migrations I ran was a XXXX_create_pages.rb which has the following code:
class CreatePages < ActiveRecord::Migration
def change
create_table :pages do |t|
t.string :name, null: false, unique: true
t.string :title, null: false
t.text :body
t.timestamps null: false
end
end
end
Any help is greatly appreciated! Thanks!
UPDATE
You need to make sure you actually execute your migrations.
Try rake db:migrate then try to run your server or console again.
Make sure to run rake db:create and then rake db:migrate and that should work.
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: pages: SELECT "pages".* FROM "pages"
From the error message, it's obvious that the pages table does not exist in your database right now. It got deleted somehow even if you did not delete it knowingly.
So, you should create the pages table again by running the corresponding migration:
rake db:migrate
In case your schema version exceeded to migration XXXX_create_pages.rb then rename you migration with greatest timestamp.
Eg.
Your page migration is
20151130203912_create_pages.rb
If your current schema version is
ActiveRecord::Schema.define(:version => 20151211175046)
Then pages migration must be 20151230203912_create_pages.rb
I hope it would be helpful.
i'm new to Ruby. I'm at RoR Getting Started Section 5.5 and after running db:migrate, got the below error. Any advise on why? I can't find any answers or solution or problem. Pls help.
$ bin/rake db:migrate
== 20150207172154 CreateArticles: migrating ===================================
-- create_table(:articles) -> 0.0017s
== 20150207172154 CreateArticles: migrated (0.0019s) ==========================
rake aborted! StandardError: An error has occurred, this and all later
migrations canceled:
wrong number of arguments (1 for 0)-e:1:in <main>' ArgumentError:
wrong number of arguments (1 for 0)
-e:1:in' Tasks: TOP => db:migrate (See full trace by running task with --trace)
Below is my migration file.
class CreateArticles < ActiveRecord::Migration def change
create_table :articles do |t|
t.string :title
t.text :text
t.timestamps null: false
end
end
end
This is an error that I ran into once, and it's because of Arel gem, to solve it, go to Gemfile, and add this line
gem 'arel', '6.0.0.beta2'
then run bundle from the terminal. If it complains about Arel, then install it from the terminal by typing bundle update arel. Then migrate your database again.
I created models, views, and controllers for 'startups' each individually (without scaffolding). I have a file db>migrate>'201..._create_startups.rb' with the code below:
class CreateStartups < ActiveRecord::Migration
def change
create_table :startups do |t|
t.string :name
t.string :location
t.string :description
t.timestamps null: false
end
end
end
I ran "bundle exec rake db:migrate" and I get this response:
== 20141126011749 CreateStartups: migrating ===================================
-- create_table(:startups)
-> 0.0155s
== 20141126011749 CreateStartups: migrated (0.0159s) ==========================
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (1 for 0)/Users/kevinmircovich/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `initialize'
Once I run my local server and go to my browser to view my app, I have the message below:
Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
Extracted source (around line #393):
392 def check_pending!(connection = Base.connection)
393 raise ActiveRecord::PendingMigrationError if ActiveRecord::Migrator.needs_migration?>.>(connection)
394 end
395
396 def load_schema_if_pending!
I ran "bin/rake db:migrate RAILS_ENV=development" and had the same error as I did when I ran "bundle exec rake db:migrate":
wrong number of arguments (1 for 0)
no need to "null: false" on timestamps: it is not users' input: those are set by the active model itself, so you can remove the argument.
In Rails migration t.timestamp macro adds two columns, created_at and updated_at. These special columns are automatically managed by Active Record if they exist.
It will automatically update when new recored created & updated.
Please remove null:false argument from t.timestamp.
class CreateStartups < ActiveRecord::Migration
def change
create_table :startups do |t|
t.string :name
t.string :location
t.string :description
t.timestamps
end
end
end
I received a similar error when running rake:db migrate. To resolve my issue I ran rake:db drop to drop my database since I was in dev mode with no production database. Then I recreate the database with rake db:create after which i ran rake db:migrate successfully.
Error running rake db:migrate
ActiveRecord::PendingMigrationError
Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue.
Resolved using:
rake db:drop - this will wipe the data out of your database
rake db:create
rake db:migrate
I want to remove a migration from my application.
I have a migration file 20141105030942_removedate_fromexpense.rb
the class file for the migrations is
class RemovedateFromexpense < ActiveRecord::Migration
def change
remove_column :expenses, :date, :date
end
end
When I give this command:
rake db:migrate:down VERSION=20141105030942
I get the following error:
== 20141105030942 RemovedateFromexpense: reverting ============================
-- add_column(:expenses, :date, :date)
rake aborted!
StandardError: An error has occurred, this migration was canceled:
SQLite3::SQLException: duplicate column name: date: ALTER TABLE "expenses" ADD "date" date/home/sumyvps/.rvm/gems/ruby-1.9.3-p545#railstutorial_rails_4_0/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize'
db:migrate:status for migration file is as below
up 20141105030942 Removedate fromexpense
Has anyone an idea why this is happening?
You do not need to specify the column type in your migration file. Just the name of the table and the column is enough to remove the column from the table.
Edit your migration file to:
class RemovedateFromexpense < ActiveRecord::Migration
def change
remove_column :expenses, :date
end
end
And then run:
rake db:migrate
This should do the work.
A common task is to rollback the last migration. For example, if you made a mistake in it and wish to correct it. Rather than tracking down the version number associated with the previous migration you can run:
rake db:rollback
This will rollback the latest migration, either by reverting the change method or by running the down method. If you need to undo several migrations you can provide a STEP parameter:
rake db:rollback STEP=3
will revert the last 3 migrations.
First Run:
rails generate migration RemoveDateFromExpense date:date
then rake db:migrate
Hope this help!
I am trying to update some default values for new columns set in a migration. However I am getting a Postgres error whenever I try to do anything with the records of users table (except modify its structure). I am using Rails 3.0.7, ruby 1.9.2 and the pg gem version 0.11.0
Here is the migration:
def self.up
add_column :users, :state_machine, :string
add_column :users, :wizard_steps_completed, :integer, :default => "1"
add_column :users, :activated_at, :datetime
User.reset_column_information
User.all.each do |u|
u.update_attributes(:state_machine => "activated", :wizard_steps_completed => 3, :activated_at => u.created_at)
end
end
The columns are added with no problems. however the changes to existing records all fail with the following error:
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== AddUserSignupInfo: migrating ==============================================
rake aborted!
An error has occurred, this and all later migrations canceled:
PGError: ERROR: current transaction is aborted, commands ignored until end of transaction block
: SELECT COUNT(*)
FROM pg_tables
WHERE tablename = 'users'
If I attempt to update any orecord it seems to work, I can only make structural changes...
Any ideas?
Turn on postgres logging (Configured in /var/lib/pgsql/data/postgresql.conf and grep for "ERROR REPORTING AND LOGGING"). Or you might want to take the SQL and run it yourself to see what error happens. It could be a constraint thats failing because of your update.