我看过rails screencast,我已经完成了:
brew install postgresql
initdb /usr/local/var/postgres
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
rails new ispiti_postgres -d postgresql
bundle install
我启动了服务器,我收到了这个错误:
读取错误:ActiveRecord :: NoDatabaseError:致命:角色“darko”不存在
然后我尝试了这个:
darko@darko-Lenovo-G570 ~/Documents/pokusi/ispiti_postgres $ bundle exec rake db:create:all
FATAL: role "darko" does not exist
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"ispiti_postgres_development"}
rake aborted!
我尝试在database.yaml
postgres
,darko
,root
中更改darko
中的用户名,然后命令使用rails db,但每次都有例如:
darko @ darko-Lenovo-G570~ / Documents / pokusi / ispiti_postgres $ rails db
psql:致命:角色“root”不存在
我尝试没有用户名,但仍然收到消息,即postgres
角色不存在。
我不知道如何访问darko@darko-Lenovo-G570 ~/Documents/pokusi/ispiti_postgres $ sudo -u postgres -i
[sudo] password for darko:
postgres@darko-Lenovo-G570 ~ $ psql
psql: FATAL: role "postgres" does not exist
。我试试这个:
# product_images/models/models.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api, tools
class PublishingStatus(models.Model):
_name = 'product_images.publishing_status'
_description = 'Publishing status'
name = fields.Char(string="Name")
slug = fields.Char(string="Slug")
class ProductImage(models.Model):
_name = 'product_images.product_image'
_description = 'Product image'
name = fields.Char(string="Alternative text")
product_id = fields.Many2one('product.product', string='Product', ondelete='set null', index=True)
original_image = fields.Binary(string='Original image')
@api.model
def _get_default_state(self):
return self.env['product_images.publishing_status'].search([['slug', '=', 'draft']])
@api.model
def _get_all_states(self, groups, domain, order):
state_ids = self.env['product_images.publishing_status'].search([])
return state_ids
state_id = fields.Many2one(
'product_images.publishing_status',
string='Publishing status',
default=_get_default_state,
group_expand='_get_all_states',
)
@api.multi
def action_set_to_draft(self):
self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'draft']])
@api.multi
def action_request_for_approval(self):
self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'pending']])
@api.multi
def action_approve(self):
self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'approved']])
@api.multi
def action_reject(self):
self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'rejected']])
由于
答案 0 :(得分:0)
我使用的是Linux 32位,LinuxBrew只能安装在64位系统上。所以brew命令无效。