Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User error on seeding db #38

Closed
acmeraptor opened this issue Nov 4, 2017 · 21 comments
Closed

User error on seeding db #38

acmeraptor opened this issue Nov 4, 2017 · 21 comments

Comments

@acmeraptor
Copy link

Hello, I'm new to ruby on rails so forgive me if this is a newbie mistake. I followed the guide here to install ruby on rails on my ubuntu server: https://gorails.com/setup/ubuntu/14.04

I then followed your guide on installing pwb. When I get to the rails pwb:db:seed step I get the following (full traced) error: https://gist.github.com/acmeraptor/152000f7a0efd9bb5642b2df5fc48728

I have tried various ways to make sure that the postgre user exists and is known in the config/database.yml file but I can't tell if my RoR setup is faulty or if I missed some intuitive step on your guide.

Any ideas?
~acme

@etewiah
Copy link
Owner

etewiah commented Nov 5, 2017

Hello there,
I don't think it is an issue with your postgres user. It seems you have successfully created the database and run the migrations so your postgres connection details are probably okay.
First of all I'd suggest you check from the console that the migrations have run successfully. To get to the console run:

rails c

From the console run this command and let me know the result:

Pwb::User.count

@acmeraptor
Copy link
Author

jasonl@wyo-jol-uws01:~/jason$ rails c
Running via Spring preloader in process 1799
Loading development environment (Rails 5.1.4)
irb(main):001:0> Pwb::User.count
(0.8ms) SELECT COUNT(*) FROM "pwb_users"
=> 2
irb(main):002:0>

--

I didn't even know how to access the rails console until now..

@etewiah
Copy link
Owner

etewiah commented Nov 6, 2017

Okay, so you really have got the db setup right. Just to be sure there isn't some corrupt data in the db or something along those lines please run the ff to destroy and recreate the database:

rails db:drop db:create db:migrate

After that try seeding the db again:

rails pwb:db:seed

If you get the same error again we might have to do some debugging with:

https://github.com/deivid-rodriguez/pry-byebug

We could arrange a skype call and I can talk you through the process.

@acmeraptor
Copy link
Author

Well, the same error occurred: (not the full trace this time)

rails pwb:db:seed
rails aborted!
ActiveRecord::RecordInvalid: Validation failed: User must exist
/home/jasonl/jason/bin/rails:9:in require' /home/jasonl/jason/bin/rails:9:in <top (required)>'
/home/jasonl/jason/bin/spring:15:in <top (required)>' bin/rails:3:in load'
bin/rails:3:in `

'
Tasks: TOP => pwb:db:seed
(See full trace by running task with --trace)

I'll do some reading on the debugging tool but it looks pretty simple to install. A skype call might be a bit of a challenge, I'd like to work with your availability since I'm on UTC -7. About to leave for work soon but I will keep up with this topic throughout the day, or I can email you at the address in your profile.

@etewiah
Copy link
Owner

etewiah commented Nov 6, 2017

Very strange. Can you go to the console again and try running this to see if it works:

Pwb::Contact.create(primary_email: "bob_a@example.com")

@etewiah
Copy link
Owner

etewiah commented Nov 6, 2017

The contacts model is actually not crucial for the website right now so you could comment out the line for seeding it as a workaround.

Just open up this file in your text editor and comment out line 58:

/home/jasonl/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/bundler/gems/property_web_builder-b86b43186d0e/lib/pwb/seeder.rb

@acmeraptor
Copy link
Author

The contact creation appears to have worked. Ill comment the part you said out when I'm not working from a mobile phone.

https://gist.github.com/acmeraptor/ef9a0d2a4077322123db417f5198bf01

@acmeraptor
Copy link
Author

acmeraptor commented Nov 6, 2017

Ok, I commented out the following line:

. def seed_contacts yml_file
. contacts_yml = load_seed_yml yml_file
. contacts_yml.each do |contact_yml|
. unless Pwb::Contact.where(primary_email: contact_yml['email']).count > 0
. # Pwb::Contact.create!(contact_yml)
. end

^^the periods were added so it was a little more readable for this site

Re-ran rails db:drop db:create db:migrate

Re-ran rails pwb:db:seed

Which now produces the following full trace, https://gist.github.com/acmeraptor/528b2016f3fc49cc6ae76ff458138327

@etewiah
Copy link
Owner

etewiah commented Nov 6, 2017

Okay, I've just done some more research into this. It seems to be to do with not declaring a couple of belongs_to relationships as optional:

https://stackoverflow.com/questions/38983666/validation-failed-class-must-exist

I have just now pushed out a fix. To update to the latest version, run this command:

bundle update pwb

Let me know if that works.

@acmeraptor
Copy link
Author

@acmeraptor
Copy link
Author

I am not depending on these versions of ruby or rails, if there is a working set of prerequisites then I can easily switch to them. My test server is just a virtual machine running on my laptop that I am using before I put anything on what I consider a production server. I am only running the versions of things now because they were recommended by a different guide.

@acmeraptor
Copy link
Author

I kind of take my last statement back. Despite the error, I now have a working test site. I think you can mark this problem as resolved. I have some other issues but I think they're not related to the one I originally posted about.

@dcallao
Copy link

dcallao commented Nov 7, 2017

hi @etewiah! I am stuck with the same error. I got rvm with ruby-2.3.4 and Rails 5.1.4. I am getting this error after I comment out the seed_contacts yml_file method above:

rails aborted!
ActiveRecord::RecordInvalid: Validation failed: Page must exist

Do you think you can help me out here? Im on Skype via dancallao

@etewiah
Copy link
Owner

etewiah commented Nov 7, 2017

Hi @dcallao, can you please try with the latest master branch of PropertyWebBuilder and let me know how that goes?

If you have the latest version you will see this in your Gemfile.lock:

remote: https://github.com/etewiah/property_web_builder
revision: 96a24e9

If you do get the error again, please copy it in full like acmeraptor did - it helps me troubleshoot.

In case that does not work we can certainly speak via Skype.

@etewiah
Copy link
Owner

etewiah commented Nov 7, 2017

Good to hear @acmeraptor - any other problems just go ahead and open another issue and I'll help you resolve it.

@acmeraptor
Copy link
Author

I'll keep up with this thread since someone else is having the same issue. The latest gist: https://gist.github.com/acmeraptor/27e549a6713e09405106e4e3a84e9e81

@etewiah
Copy link
Owner

etewiah commented Nov 7, 2017

Sorry guys, I missed out on adding the "optional: true" statement in the belongs_to page relationship for the link model.
Just added that now.
Run "bundle update pwb" once more to update to the latest and try running the seed task again.

@acmeraptor
Copy link
Author

I'd say you've nailed it. rails pwb:db:seed & rails pwb:db:seed_pages completed without errors.

https://gist.github.com/acmeraptor/d45bbb6cca9dafebeaea10d872739951

@etewiah
Copy link
Owner

etewiah commented Nov 7, 2017

Great. I'll wait for confirmation from @dcallao and then I'll close this issue.

@dcallao
Copy link

dcallao commented Nov 9, 2017

@etewiah yup! it works now! Thx.

@etewiah
Copy link
Owner

etewiah commented Nov 9, 2017

Thanks for confirming @dcallao. I'll close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants