Ruby DB Migration Error 'rake db:migrate' - ruby-on-rails

I am starting to play around with ruby and setting up my development environment.
I am referencing This Ruby on Rails 'Getting Started Guide' and am down to section 5.5 'Running a Migration'
The problem is when I run the following command
rake db:migrate
I get the following error
C:\Users\someuser\RubymineProjects\my_app>rake db:migrate
rake aborted!
SyntaxError:C:/Users/someuser/RubymineProjects/my_app/db/migrate/20140718160751_create_articles.rb:4: syntax error, unexpected '[', expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
t.string :[title
^
C:/Users/someuser/RubymineProjects/my_app/db/migrate/20140718160751_create_articles.rb:5: syntax error, unexpected ']', expecting keyword_end
t.text] :text
^
C:in `disable_ddl_transaction'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Any idea what is causing this and how to fix it?

It looks like you have some extra brackets in your migration that don't belong there. The migration should look like:
class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.string :title
t.text :text
t.timestamps
end
end
end

Related

rake aborted ! name error uninitialized constant Rails :: API :: Rdoc

When i am trying to run rake db:migrate in my rails I get this error:
rake aborted ! name error uninitialized constant Rails :: API :: Rdoc
I am a newbie in the ruby on rails I was following the youtube tutorial to build a web blog application: https://www.youtube.com/watch?v=BI_VnnOLSKY
but in the video it runs rake db just fine, i am so confused why I got rake aborted error in the command prompt, the migration file code is:
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
t.timestamps
end
end
end
would you please help me with this?

RoR Tutorial Section 5.5 db:migrate error

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.

Why am I getting: Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development

I am a total newbie to Rails, and I am following the Railsbridge Intro to Rails. I have created my project and now I am trying to create a new controller action for voting, and a new route for voting. When I go to the development page, it shows the following message:
Migrations are pending. To resolve this issue, run: bin/rake
db:migrate RAILS_ENV=development
In the command line it gives me this information:
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `migrate' for #<ActiveRecord::ConnectionAdapters::TableDefiniti
on:0x5d79e78>C:/Sites/railsbridgejan/suggestotron/db/migrate/20150129195744_create_votes.rb:6:in `block in change' C:/Sites/railsbridgejan/suggestotron/db/migrate/20150129195744_create_votes.rb:3:in `change'
C:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
So, when I look in my db files for create_votes.rb this is what it looks like:
class CreateVotes < ActiveRecord::Migration
def change
create_table :votes do |t|
t.integer :topic_id
t.string :rake
t.migrate :db
t.timestamps null: false
end
end
end
Is there something wrong with my file's code? t.migrate :db is line 6, which according to the command line, is the problem. I am using Rails 4, Ruby 2, and Sqlite. I had tried to install MySql, but I ran into some major issues, so I just continued with Sqlite. Could that be causing this problem at all? It seems like the issue is in the code listed above, but I'm not sure.
Thank you!
Inside the change method you use
t.migrate :db
The migrate data type doesn't exist. I assume you wanted to use a String.
t.string :db

heroku migration fails

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

Ruby on Rails - error running server

am currently working on a rails project. When i tried to start rails server its throwing the following error:
=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/var/lib/gems/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters
/sqlite_adapter.rb:439:in `table_structure': Could not find table 'dbrick'
(ActiveRecord::StatementInvalid)
My table name is 'dbrick'. I also Tried to rake db:drop and rake db:mirgrate. While migrating its throwing the following error:
rake aborted!
Could not find table 'dbrick'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
This is my migrate file:
class CreateDbricks < ActiveRecord::Migration
def self.up
create_table :dbricks do |t|
t.text :description
t.string :video
t.string :video_html
t.string :image_id
t.string :option_id
t.boolean :choice
t.string :reach
t.integer :category_id
t.string :user_id
t.datetime :deleted_at
t.timestamps
end
end
def self.down
drop_table :dbricks
end
end
It will be so much help full if any one help me out of this.
Thanks in advance.
I would try :
rake db:schema:load
To load your schema ( to which I believe its finding the error against your DB ).
If that fails, I would manually find the migration that creates your dbrick, locate the name of the file and copy and paste the number in the filename to produce this :
rake db:migrate:down VERSION=123412341234 # <-- where the number is the number you pasted
Look for errors. Occasionally one thing exists already, or doesn't exist already and prevents the migration from running all the way, and consequentially that would be the source of your error. If it goes successfully then rake it back up :
rake db:migrate:up VERSION=123412341234 # <-- where the number is the number you pasted
If it doesn't go successfully, then you'll have to put on your miner's helmet, and get your hands dirty with :
rails dbconsole
Which will take you into your database and you'll have to manually delete whatever table/column is preventing the migration from occurring. Once that is fixed, exit out and rake db:migrate:up!
Have you migrated your database? rake db:migrate
If you have, drop your database (this deletes all data, so be careful - do it if you do not care about losing data in your db)
rake db:drop
This will clear out your database, and your schema. Then
rake db:migrate
This will re-migrate your schema.

Resources