I\'m using rails 4.1.5 with postgresql 9.1 under Debian 7, and I\'m not able to create a database in my development environment. When I run
bin/rake db:create
>
I had the same problem and in my case, I had used Answer.column_name
in a validation in the Answer model itself. Because test database was already created on my local so RAILS_ENV=test rails db:create
was working fine on local, but giving the same error in CI/CD pipeline
It was due to the reason that Rails load all the files inside app/ directory before running db:create
command, and at that time as no database is there Answer.column_names
failed.
I used something like this:
validates_uniqueness_of :content, scope: (Answer.column_names - %w[id created_at updated_at]).map(&:to_sym), message: 'Duplicate answer'
which is wrong. Then I changed to:
DUPLICATE_ANSWER_SCOPE = %i[content question_id session_id]
validates_uniqueness_of :content, scope: DUPLICATE_ANSWER_SCOPE, message: 'Duplicate answer'