Heroku run python manage.py migrate -> ......ImportError: No module named production


#1

Hi. I’m almost done with the book, but I am having trouble in the chapter about deploying a web app. I cannot figure out why there is an error message after typing “heroku run python.py migrate”. Below is the message shown in the terminal after the command.

Running python manage.py migrate on ⬢ ryujihellowebapp… up, run.6099 (Free)
Traceback (most recent call last):
File “manage.py”, line 10, in
execute_from_command_line(sys.argv)
File “/app/.heroku/python/lib/python2.7/site-packages/django/core/management/init.py”, line 353, in execute_from_command_line
utility.execute()
File “/app/.heroku/python/lib/python2.7/site-packages/django/core/management/init.py”, line 302, in execute
settings.INSTALLED_APPS
File “/app/.heroku/python/lib/python2.7/site-packages/django/conf/init.py”, line 55, in getattr
self._setup(name)
File “/app/.heroku/python/lib/python2.7/site-packages/django/conf/init.py”, line 43, in _setup
self._wrapped = Settings(settings_module)
File “/app/.heroku/python/lib/python2.7/site-packages/django/conf/init.py”, line 99, in init
mod = importlib.import_module(self.SETTINGS_MODULE)
File “/app/.heroku/python/lib/python2.7/importlib/init.py”, line 37, in import_module
import(name)
ImportError: No module named production

Also, I cannot connect to the url after typing “heroku open” as well. Not sure if these are a related problem or not. I could manage to push to heroku and rename the app though.

Thank you.


#2

What does your settings_production.py look like? Can you paste it into something like pastebin,com and share the link?


#4

Hm, okay, that looks fine. :|

You recall doing both of these steps and things working fine?


#5

Ok, I followed the step carefully once more and now it worked this itme! Both of the migrating and creating superuser were done successfully.

However… When I type “heroku open”, the app doesn’t show up still. There is an error message saying:


Internal Server Error

The server encountered an unexpected internal server error

(generated by waitress)


Everything seems to be working perfectly in localhost.


#6

What do the Heroku logs say? http://stackoverflow.com/questions/2671454/heroku-how-to-see-all-the-logs


#8

What does the python manage.py collectstatic command do when you run it? https://github.com/evansd/whitenoise/issues/37


#11

Ok, so I worked on it for hours and now the app is on server! It started to show up as soon as I commented out this part (in settings_production.py ):

STATICFILES_STORAGE = ‘whitenoise.django.GzipManifestStaticFilesStorage’
.

But when I check heroku logs, I can still an error message:

WARNING:django.request:Not Found: /static/css/style.css http://pastebin.com/fg1aYAWh

#12

Yeah, still looks like the staticfiles migration isn’t happening when you deploy to Heroku. Have you gone through all the steps in the book again to make sure something isn’t missed?


#13

Yes, I just did the whole chapter again. The app doesn’t show up. I see only the error message from waitress. But If I comment out this part in settings_production.py :

STATICFILES_STORAGE = ‘whitenoise.django.GzipManifestStaticFilesStorage’

The webpage shows up but with no css file is found.So Definitely something is wrong with the code.

Additionally, this is what I get after typing python manage.py collectstatic. Another erroe message at the bottom too.

http://pastebin.com/DJXvdZW2


#14

Hm, are you missing the empty static folder?


#15

No, it exists with a empty robots.txt in. The book says it’s supposed to be in the same folder as settings.py. But if I look at the codes in the github, it’s in the root folder( same as manage.py). Which one is correct? I tried both and neither worked. I tried almost everything I could find online but none of the solutions worked for me…


#16

Hm the screenshot that I have above shows that it’s supposed to be in the same folder as manage.py, not settings.py. Where are you reading that? (It’s supposed to be in root.)


#17

Amazon kindle version.

Either way, that wasn’t a problem. Any other solutions that you can think of?


#18

Here are all the code I have.


#19

Whaaaat. That’s so weird! Looking into updating Kindle…

I’ll see about installing/running your app on my end in the next couple days to see if I can get it to work! Thanks for sharing the github link. :)


#20

Thank you! I will keep working on it.


#21

Oh hey — do you have __init__.py in your .gitignore file?

They’re not in your github repo, and they’re necessary for Python to know that a directory is python module. That would explain why it would work locally but not under Heroku, since in order to run the project, Heroku would need those files. :)


#22

No. I don’t know why but my .gitigmore file was renamed automatically to db.sqlite3. I deleted it and created a new .gitignore file. I tried to include __init__.py in but either way, it didn’t work.

I tried to add the line below in Procfile,

web: python manage.py collectstatic --noinput

as suggested here,

http://stackoverflow.com/questions/14253978/heroku-performing-collectstatic-as-expected-on-deployment,

Then I typed heroku logs, I saw this successful message : 58 static files copied to '/app/staticfiles', 58 post-processed. But when I go to the browser, I still see an error message (this time default one that says applcation error instead of the one from waitress like before)


#23

No no, the __init__.py files shouldn’t be ignored. Make sure they’re viewable by Git, commit them (since Heroku needs them), push to github too so I can see them, and see if that changes anything.