# Using Locomotive - Problem making database tables

**URL:** <https://www.ruby-forum.com/t/using-locomotive-problem-making-database-tables/78819>\
**Category:** Rails\
**Created:** [December 8, 2006, 8:31pm UTC](https://www.ruby-forum.com/t/using-locomotive-problem-making-database-tables/78819 "2006-12-08T20:31:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmcfarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@cmcfarland](https://www.ruby-forum.com/u/cmcfarland)\
**Post date:** [December 8, 2006, 8:31pm UTC](https://www.ruby-forum.com/t/using-locomotive-problem-making-database-tables/78819/1 "2006-12-08T20:31:54Z")

</div>

Hi,

Im using a macbook and Im still trying to get rails running properly!  
I’ve went through the basic locomotive help file and have no problems  
up until ‘Prepare your database tables’.  
Here is what im trying to do:

"Prepare your database tables

We will prepare our database using Migrations. Using migrations, you  
code your table schemas in ruby. The migrations system is set up to  
facilitate the evolution (and devolution!) of your schema over time  
(versions/features/etc.).

Select your application in the Locomotive main window and choose  
Applications \> Open Terminal  
On the command line in the terminal type:  
ruby script/generate migration add\_monkeys\_table

(The name you choose for your migration is not all that important to  
rails; it should not include spaces and it should be meaningful to  
you).  
Open the newly created ‘001\_add\_monkeys\_table.rb’ in db/migrate in your  
favorite text editor. It should look something like this:  
class AddMonkeysTable \< ActiveRecord::Migration  
def self.up  
end

def self.down  
end  
end

Modify this code to look like this:  
class AddMonkeysTable \< ActiveRecord::Migration  
def self.up  
create\_table :monkeys do |t|  
t.column :name, :string  
t.column :angry?, :boolean  
end  
end

def self.down  
drop\_table :monkeys  
end  
end

To create the table specified by this migration, from the command line  
in the terminal (opened previously from Locomotive), type:  
rake migrate

Success! Move on to generating scaffolding to make use of your new  
database table."

No problems up until the step 6, rake migrate. Here is the error:

"c0a80004:~/Documents/work/depot jim$ ruby script/generate migration  
add\_monkeys\_table  
create db/migrate  
create db/migrate/001\_add\_monkeys\_table.rb  
c0a80004:~/Documents/work/depot jim$ rake migrate  
(in /Users/jim/Documents/work/depot)  
rake aborted!  
Unknown database ‘depot\_development’

(See full trace by running task with --trace)  
c0a80004:~/Documents/work/depot jim$ "

I can see it is obviously something with the database, I have a clean  
install of mySQL installed as recommended on the locomotive site. Can  
anyone help me identify what I am doing wrong so I can get coding with  
Rails!

Help much appreciated, thankyou in advance.

---

<div class="post-metadata">

**Author:** ![cmcfarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@cmcfarland](https://www.ruby-forum.com/u/cmcfarland)\
**Post date:** [December 8, 2006, 8:53pm UTC](https://www.ruby-forum.com/t/using-locomotive-problem-making-database-tables/78819/2 "2006-12-08T20:53:06Z")

</div>

cmcfarland wrote:

> Unknown database ‘depot\_development’

I don’t know about locomotive, but generally you have to manually create  
your actual database, rails can’t do that for you. Using whatever  
database admin that you use you must create a database called  
depot\_development, or point it to different database name in  
config/database.yml

Than you migration should work like a charm.

---

<div class="post-metadata">

**Author:** ![cmcfarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@cmcfarland](https://www.ruby-forum.com/u/cmcfarland)\
**Post date:** [December 8, 2006, 9:58pm UTC](https://www.ruby-forum.com/t/using-locomotive-problem-making-database-tables/78819/3 "2006-12-08T21:58:07Z")

</div>

Then the question is exactly how do I manually create the database? Any  
pointers on this. I’m finding it hard to understand how my locomotive  
setup and my mysql setup (which allows me to do nothing other than run  
it or turn it off) connect and how I get these databases and tables set  
up.

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![cmcfarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@cmcfarland](https://www.ruby-forum.com/u/cmcfarland)\
**Post date:** [December 9, 2006, 12:32am UTC](https://www.ruby-forum.com/t/using-locomotive-problem-making-database-tables/78819/4 "2006-12-09T00:32:28Z")

</div>

This procedure talks about MySQL 4, but the stuff like setting the  
root password has to be done with MySQL 5 too.  
[http://www.entropy.ch/software/macosx/mysql/](http://www.entropy.ch/software/macosx/mysql/)

For creating databases:  
[http://cocoamysql.sourceforge.net/beta/CocoaMySQL\_0.7b5.zip](http://cocoamysql.sourceforge.net/beta/CocoaMySQL_0.7b5.zip)

For creating your table structure: use migrations that are  
automatically created in the db folder when generating models. Check  
the Rails API for instructions.

On 08 Dec 2006, at 21:57, cmcfarland wrote:

> Then the question is exactly how do I manually create the database?  
> Any  
> pointers on this. I’m finding it hard to understand how my locomotive  
> setup and my mysql setup (which allows me to do nothing other than run  
> it or turn it off) connect and how I get these databases and tables  
> set  
> up.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![cmcfarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@cmcfarland](https://www.ruby-forum.com/u/cmcfarland)\
**Post date:** [January 10, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/using-locomotive-problem-making-database-tables/78819/5 "2007-01-10T22:16:33Z")

</div>

On Jan 10, 7:54 am, “cmcfarland” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> install)  
> Also just to check I have this right… After I have the databases made  
> I just need to set the details in config/database.yml and then I can  
> start creating my table structures using migrations?
> 
> Is there an easier way to make a database? Or can someone give me some  
> help making the requred databases to use with the above example.
> 
> Help greatly appreciated. I’m getting frustrated just trying to get  
> things set up so I can start coding!
> 
> Thanks for your help.  
> Hi,

I would (very strongly) suggest using sqlite to start - you don’t need  
what mysql provides over sqlite at this point in your exploration of  
rails (you may never need what mysql provides over sqlite!).  
Configuring sqlite is also _substantially_ easier as the migration  
_can_ create the database for sqlite.

Set up your database.yml to have (remove the username: password: etc  
lines altogether)

development:  
adapter: sqlite3  
database: db/dev.db

and you’re done! Run the migration and it will create the db and the  
tables. (The database will be the file /path/to/yourapp/db/dev.db)

Best,

-r

---

<div class="post-metadata">

**Author:** ![cmcfarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@cmcfarland](https://www.ruby-forum.com/u/cmcfarland)\
**Post date:** [January 10, 2007, 1:55pm UTC](https://www.ruby-forum.com/t/using-locomotive-problem-making-database-tables/78819/6 "2007-01-10T13:55:35Z")

</div>

Thankyou for your comments. I know have mysql installed properly as far  
as I can see.

How do I actually make these databases? I’ve installed CocaMysql2 and  
when I try to make a new database for depot\_development, to work with  
the above that ive been trying to get working, im having problems.

> From File \> New, Ive completed the fields:  
> Host: localhost  
> User: root  
> Password: (i have added my password that i set following the mysql  
> install)  
> Database: depot\_development

I dont know about SSH Password etc so I havent completed that part.

When I try to connect it just errors ‘connection failed’.

Out of the example on locomotive and also from the examples in a rails  
book, it never seems to mention making the databases so i am completely  
confused how to make them. Obviously I need to get this figured out!

Also just to check I have this right… After I have the databases made  
I just need to set the details in config/database.yml and then I can  
start creating my table structures using migrations?

Is there an easier way to make a database? Or can someone give me some  
help making the requred databases to use with the above example.

Help greatly appreciated. I’m getting frustrated just trying to get  
things set up so I can start coding!

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![cmcfarland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@cmcfarland](https://www.ruby-forum.com/u/cmcfarland)\
**Post date:** [January 10, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/using-locomotive-problem-making-database-tables/78819/7 "2007-01-10T23:09:28Z")

</div>

cmcfarland wrote:

> Thankyou for your comments. I know have mysql installed properly as far  
> as I can see.
> 
> How do I actually make these databases? I’ve installed CocaMysql2 and  
> when I try to make a new database for depot\_development, to work with  
> the above that ive been trying to get working, im having problems.
> 
> > From File \> New, Ive completed the fields:  
> > Host: localhost  
> > User: root  
> > Password: (i have added my password that i set following the mysql  
> > install)  
> > Database: depot\_development
> 
> I dont know about SSH Password etc so I havent completed that part.
> 
> When I try to connect it just errors ‘connection failed’.

Sounds like the MySQL server hasn’t started. Install the system  
preference pane and start it up. CocaMysql should then be able to login  
to the DB server. From there create a new database by clicking the “+”  
icon found under “Choose database”.

Ryan is right in recommending sqlite - it makes life a lot easier and  
will do the job for most smallish projects.
