LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-23-2009, 07:43 AM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
Ruby on Rails - create tables


Hi. I am trying to figure out Ruby on Rails and I have this migration file:

Quote:
class AddTable < ActiveRecord::Migration
def self.up
create_table :photos do |t|
t.column :name, :string, :limit => 50, :null => false
t.column :path, :string, :limit => 100, :null => false
t.column :date, :datetime, :null => false
t.column :camera, :string, :limit => 20, :null => false
t.column :resolution, :string, :limit => 20, :null => false
t.column :album, :string, :limit => 30, :null => false
t.column :shutter, :integer, :null => false
t.column :fstop, :float, :null => false
t.column :caption, :string, :limit => 100, :null => false
end
create_table :photoalbums do |t|
t.column :name, :string, :limit => 50, :null => false
t.column :date, :datetime, :null => false
t.column :description :string, :limit => 100, :null => false
end
end
def self.down
drop_table :photos
end
end
When I run "rake db:create" it creates the table schema_migrations but it doesn't create any tables for me. How do I do that?

Am I forced to do it the old fashioned way using SQL?

Last edited by Ephracis; 02-23-2009 at 07:43 AM. Reason: turn off smileys
 
Old 02-23-2009, 09:36 AM   #2
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
What's in your config/database.yml file? That should specify what kind of database to create. My guess is that there is a database created, but it has no data in it yet. To populate it, you need either to enter in test data or fire up the application and add data.

Take a look at this page: http://guides.rails.info/getting_sta...ringa-database

Edit: please use [code][/code] blocks for code, rather than [quote][/quote]. It makes them easier to read.

Last edited by Telemachos; 02-23-2009 at 09:47 AM.
 
Old 02-23-2009, 09:40 AM   #3
JMather
LQ Newbie
 
Registered: Feb 2009
Posts: 1

Rep: Reputation: 0
You need to run "rake db:migrate"
 
Old 02-23-2009, 09:44 AM   #4
Lee_Ball
Member
 
Registered: Jul 2005
Location: Manchester (UK)
Distribution: Fedora CentOS
Posts: 132

Rep: Reputation: 18
See http://guides.rails.info/getting_sta...inga-migration for background on JMathers answer.
 
Old 02-23-2009, 09:44 AM   #5
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by JMather View Post
You need to run "rake db:migrate"
Yeah, I mistyped so that's what I ment. But I found out that I had to create a model before doing the migration.

Now I get a table when I migrate but there's no columns created in it. I tried to change the field to integer, tried removing the limit and null stuff, nothing worked. I don't get any columns in the database when I migrate.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Any issues installing Ruby Gems and Ruby on Rails in Slackware? Lufbery Slackware 8 02-09-2011 07:22 PM
LXer: Create Web services with Ruby on Rails and Action Web Service LXer Syndicated Linux News 0 11-05-2008 06:00 PM
LXer: How to Create Many to Many Relationships in Ruby on Rails LXer Syndicated Linux News 0 07-08-2007 03:16 AM
PHP v Ruby/Ruby on Rails Neko_D Linux - General 4 02-08-2007 11:56 PM
LXer: Ruby off the Rails LXer Syndicated Linux News 0 12-24-2005 04:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration