简体   繁体   中英

How to make Postgresql Hstore work with rails 4 on ubuntu

所以我读了一些我在Google上找到的如何用Rails 4制作hstore的文章,碰巧它并没有那么容易地被告知,所以我决定描述为使其能够工作而必须采取的步骤。 UBUNTU机器...

The steps to activate and use Hstore:

1) You need to create a migration with something like this:

def change
  enable_extension "hstore"
end

2) As it was for me, I had to install the thing called

postgresql-contrib

on my ubuntu machine, which I did with apt-get command. Perhaps you may need to add a version of your postgresql to the end of the packet name, like this:

postgresql-contrib-9.3

3) Now you can add migrations that add "hstore" fields to the tables, notice that these migrations should be following after the one that activates Hstore

4) Before u run the migrations, you might have to change to the root user of your DB and give the user that u use to access the db (most likely used in the database.yml file) an allowance to add this kind of columns, I did it with the following commands:

sudo -u postgres psql

(where postgres is the root user of the db )

and in the command line of the database write:

alter user [rails account name] with superuser;

5) Run the migrations

6) Change the user allowance back to the way it was with the following command:

alter user [rails account name] with nosuperuser;

That's it, now u should be able to use the hstore...

PS I am a bit of a newbie so perhaps I made some mistakes or something, but I hope its all fine :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM