# How to create a table using ActiveRecord alone

**URL:** <https://www.ruby-forum.com/t/how-to-create-a-table-using-activerecord-alone/148311>\
**Category:** Ruby\
**Created:** [September 11, 2008, 5:14pm UTC](https://www.ruby-forum.com/t/how-to-create-a-table-using-activerecord-alone/148311 "2008-09-11T17:14:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [September 11, 2008, 5:14pm UTC](https://www.ruby-forum.com/t/how-to-create-a-table-using-activerecord-alone/148311/1 "2008-09-11T17:14:21Z")

</div>

Hi all,

I know I can create a table by running MySql first. I search some  
tutorials on google but they all talk about creating a table using  
MySql-like database then use ActiveRecord to connect them. I wonder if  
it is possible to create a table with ActiveRecord only.

Thanks,

Li

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [September 11, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/how-to-create-a-table-using-activerecord-alone/148311/2 "2008-09-11T17:31:04Z")

</div>

On Sep 11, 2008, at 5:07 PM, Li Chen wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

You could use migrations. But thats just another way of describing the  
table.

If you want another approach (defining a model and then letting the  
abstraction  
layer create the required database), you could use datamapper  
instead[1](http://www.datamapper.org).

Then, you class will look like this:

1 class Post  
2 include DataMapper::Resource  
3 property :id, Integer, :serial =\> true  
4 property :title, String  
5 property :subtitle, String :lazy =\> [:show]  
6 property :body, Text :lazy =\> [:show]  
7 property :views, Integer, :lazy =\> [:show]  
8 property :summary, Text  
9 end

#and

Post.auto\_migrate!

will create/migrate your table automatically.

Regards,  
Florian

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [September 11, 2008, 8:03pm UTC](https://www.ruby-forum.com/t/how-to-create-a-table-using-activerecord-alone/148311/3 "2008-09-11T20:03:29Z")

</div>

Florian G. wrote:

> If you want another approach (defining a model and then letting the  
> abstraction  
> layer create the required database), you could use datamapper  
> instead[1](http://www.datamapper.org).
> 
> Then, you class will look like this:

> 

I visit the wetsite: [http://www.datamapper.org](http://www.datamapper.org). It says it is not good  
under window system. I wonder how good it is under Vista.
