-1

Sometimes ago I created database and a table in MySQL with these statements :

CREATE DATABASE amiref;
USE amiref;
CREATE TABLE refoo
(
  f1 VARCHAR(20) ,
  f2 VARCHAR(30) NOT NULL ,
  f3 INT ,
  PRIMARY KEY(f1)
);
CREATE TABLE IF NOT EXISTS users
(
  user_id1 VARCHAR(20) NOT NULL ,
  user_id2 VARCHAR(50) ,
  password VARCHAR(30) ,
  email VARCHAR(50) ,
  PRIMARY KEY(user_id1,user_id2)
);

know I want to create those database and tables in ruby on rail with model. how can I do it? please help me. thanks

ainternet73
  • 117
  • 2
  • 8

1 Answers1

2

You do this using migrations. This is a real basic thing you should learn it from the scratch! You will find the documentation here:

http://guides.rubyonrails.org/migrations.html

THe migrations are included when you creat your models using the scaffolder => http://guides.rubyonrails.org/getting_started.html#getting-up-and-running-quickly-with-scaffolding

//Also increase your acceppt rate!

An example of a migration:

Create a migration =>

rails g migration testMigration

Then youl find the migration in db/migrate. To create a table add:

create_table :table_name do |f|
     f.integer :integer_column1
     f.string :string_column1, :string_column2
     f.boolean :boolean_column1
end

Then run the migration

bundle exec rake db:migrate
davidb
  • 8,884
  • 4
  • 36
  • 72