nickjj / build-a-saas-app-with-flask

Learn how to build a production ready web app with Flask and Docker.
https://buildasaasappwithflask.com
MIT License
959 stars 189 forks source link

Error importing module db: #31

Closed elie-h closed 8 years ago

elie-h commented 8 years ago

Hi Nick, I'm trying to run the app on OSX. When I try to initialise the database I keep getting:

elieh$ run db reset catwatch catwatch_test
Error importing module db:
db

I ran docker-compose up beforehand. Any ideas?

nickjj commented 8 years ago

If you're using OSX you're probably running everything through the docker toolbox.

You'll need to use your docker machine IP address instead of localhost in a few places. Goto the config/settings.py file and do a find/replace on localhost to YOUR_DOCKER_MACHINE_IP.

You can find out your docker machine's IP address by running: docker-machine ip default.

In this case the error is likely due to it not being able to find postgres running on localhost.

For getting more informative errors when running CLI commands change this: https://github.com/nickjj/build-a-saas-app-with-flask/blob/master/cli/cli.py#L37-L44

To remove the try/catch block by changing that to:

    if sys.version_info[0] == 2:
        name = name.encode('ascii', 'replace')
        mod = __import__('cli.commands.cmd_' + name,
                         None, None, ['cli'])
nickjj commented 8 years ago

Also on a semi-related note, make sure you use named docker volumes instead of using a path in the docker-compose.yml file.

I created a gist the other day to help someone else on OSX. It contains a work flow for my previous comment as well as what I just mentioned above.

Let me know if this works for you: https://gist.github.com/nickjj/7c3a2a3447a06a1d9a66

elie-h commented 8 years ago

Ok great it works now! had to replace the local hosts with the IP.

From the notes I followed it said to delete the lines regarding volumes for Mac users. I'll try that solution out and let you know if I have any issues.

nickjj commented 8 years ago

@eliehamouche Did it work? If so, please close this ticket.

nickjj commented 8 years ago

Closing after 2+ weeks of inactivity, it's likely fixed. Please re-open it if it didn't.