Django: What do you do when some tables aren't created, and no errors are output during syncdb? - django

My apps are installed. They used to work. Now that I made some edits here and there, I must have a syntax error, or something. Instead of telling me, Django just creates the Auth, Admin, etc apps and kills all my apps. Why? And, how can I debug?

Pass --traceback to manage.py.

Yes there are couple of places where djagno doesn't give you any useful info on error. Usually, i run manage.py validate. If that is not enough, i'll try manage.py shell and import my models by hand and see what happens.

Related

Django south cannot import required field

I upgraded to django to 1.6.x which no longer has localflavor. localflavor was moved from django.contrib to its own module, which I now use in my app. When I do a schemamigration, south tries to preform this change on the database. (Note: the two modules are very closely related if not entirely similar and are cross compatible.)
The problem is that south still tries to import django.contrib.localflavor, which does not exist.
What is the correct way to fix this?
This is the error I get (running through fabric):
ValueError: Cannot import the required field 'django.contrib.localflavor.us.models.USStateField'
Fatal error: local() encountered an error (return code 1) while executing 'python manage.py migrate --settings=settings.local'
Are you still having this issue? I just ran into this and figured out the solution.
First open up your latest myapp/migration/0001_blah_blah_blah.py migration for for your app.
Then find the go to the models dict or just ctrl+f django.contrib.localflavor.us.models.USStateField and replace it with localflavor.us.models.USStateField.
After that you should be able to run ./manage.py schemamigration myapp --auto successfully and then apply the migration.
Hope this helps and it's not too late!
Cheers.

TastyPie Migration

I am getting the following error
After python manage.py syncdb
It says everything is synced, but then I see this
Not synced (use migrations):
- tastypie
How do I sync tastypie?
I also have South synced. As apparently that makes a difference.
The following SO question referred to this problem but did not solve it or at least I did not understand the solution: South manages a new app instead of syncdb
Can you please help me with this, thanks.
Keep in mind that this is my first time using Django
I saw another solution online but it required the app name and I put the app name down but it did not work (or maybe i don't know my app name). How do you find out the app name?
django-admin.py migrate tastypie

django: cannot import settings, cannot login to admin, cannot change admin password

It seems that I am completely lost here. Yesterday I noticed that I cannot login to the admin panel (don't use it much, so it's been some weeks since last login). I thought that I might have changed the admin password and now I can't remember it (though I doubt it).
I tried django-admin.py changepassword (using django 1.2.1) but it said that 'changepassword' is unknown command (I have all the necessary imports in my settings.py. Admin interface used to work ok).
Then I gave a django-admin.py validate. Then the hell begun. django-admin.py validate gave me this error: Error: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
I then gave a set DJANGO_SETTINGS_MODULE=myproject.settings
and then again a django-admin.py validate
This is what I get now: Error: Could not import settings 'myproject.settings' (Is it on sys.path? Does it have syntax errors?): No module named myproject.settings
and now I am lost. I tried django console and sys.path.append('c:\workspace') or sys.append('c:\workspace\myproject') but still get the same errors.
I use windows 7 and my project dir is c:\workspace. I don't use a PYTHONPATH variable (although I tried setting it temporarily to C:\workspace but I still get the same error). I don't use Apache, just the django development server.
What am I doing wrong? My web page works fine. I think that the fact that I can't login as admin is related to the previous import error, no?
PS: I also tried this: http://coderseye.com/2007/howto-reset-the-admin-password-in-django.html but still I couldn't change admin password for some reason. Although I could create another admin user (with which I couldn't login).
-EDIT- I forgot to mention that I use postgresql.
django-admin.py doesnot have changepassword option;
python manage.py does

What is the best Django syncdb crash debugging technique?

What is the best Django syncdb crash debugging technique ?
I've previously asked a question about a problem with manage.py syncdb returning an exception
and the answer was that the app has a wrong import.
django manage.py syncdb not working?
I'd like to know the technique used to find the place where there is a wrong import.
I tried ./manage.py syncdb --verbosity=2 but I didn't get any more information that way.
You look at the problem the other way around.
syncdb doesnt have anythin to do with "import". You have misconfigured python or/and django install and this is a problem.
If you want to debug what happen with sql queries then you should use
python manage.py sqlall __yourappname__

What is the correct configuration for %autoreload in a Django ipython shell?

Ipython has a plugin called autoreload that will presumably reload all your modules after every command, so you can change the source and not have to quit the shell and reenter all your commands. See http://dsnra.jpl.nasa.gov/software/Python/tips-ipython.html for example.
However, this seems flaky at best when using it with Django, e.g.
python manage.py shell
gives me an IPython shell with Django context, but the autoreloading does NOT seem to work reliably at all.
Here's what I have added to my ipy_user_conf.py file:
def main():
... # rest of the fn here
import ipy_autoreload
ip.magic('%autoreload 2')
The autoreloading works in limited cases, maybe 10-20% of the time.
Has anyone successfully configured this to work with Django?
This answer might also be applicable to your situation. Django keeps its own cache of all models, so if you want to reload everything, you have to clean this cache manually.