What is the best Django syncdb crash debugging technique? - django

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__

Related

django programming error : column does not exist

Hello I am running a django app using Django. The app is working correctly . But when I add a new field in my model.py I got this error
ProgrammingError at /admin/challenges/challenge/
column challenge.category does not exist
LINE 1: ..., "challenge"."modified_at", "challenge"."title", "challenge...
I found similar questions but they didn't solve my problem.
I tried to run "python manage.py migrate" and it doesn't solve the problem
Could any one help me please ?
I think you have not done make migration command. Perform
python manage.py makemigrations
and then use command
python manage.py migrate

Why is my makemigrations not creating table

I know this question has been asked before ,but not resolved .When ever i run django makemigrations and migrate, it does not create a my table in the data base .I have done research but yet, do not understand why this is happening and how i can resolve it .Any one has faced such a problem before and resolved it .Please share your solution thanks in davance
A couple of things are required to make a migration do something.
python manage.py makemigrations (builds instructions), python manage.py migrate actually alters the db specified in your settings.py
You must have a db specified in settings.py
This looks at the apps added in settings.py, if you modify a models.py for an app not added in the settings then it won't show up.

What command can allow me to recreate the django_admin_log table?

I deleted that table (whoops), and now I'd like to regenerate it. Is there a command that allows me to do that? Looking online, everyone is saying to use the command ./manage.py syncdb, but that command is no longer available in the most recent version of Django. So I tried ./manage.py migrate, but that didn't generate the table. I also tried ./manage.py --run-syncdb, but that didn't do it either.
I'm pretty sure I can do it by hand, but I'm hoping there's a way to do this with a built-in command.
Since the admin app only has one table, django_admin_log, you can revert all migrations for the admin app by running
python manage.py migrate admin zero
then re-apply the the admin app migrations by running
python manage.py migrate
You might want to create a backup before doing this (or any migration, really) :)

django - schema migration - how to add a field

I have a django 1.8 app working with a db.
I'm trying to change the schema of a table using the built-in migration.
Here are the steps I did:
In my dev invironment, I grabbed the app source and ran
python manage.py sycdb
then I ran
python manage.py loaddata ~/my_data.json
then I modified modes.py. Added a field and renamed a field...all from the same table 'TABLE1' which had no data.
then
python manage.py makemigrations myapp
python manage.py migrate
Error: django.db.utils.OperationalError: table "myapp_someother_table" already exists
then ran
python manage.py migrate --fake-initial
worked!
but when I browsed to the admin page for TABLE1, I get this error:
OperationalError: no such column: myapp_table1.my_new_field_id
I checked the db and yes, there is no such column.
How can I procceed from here? I prefer to fix this via django.
If I fix it straight in the db, then the migration goes out of sync.
Migrations do not automagically see that you have made changes. Migrations detect changes by comparing the current model with the historical model saved in the migration files.
In this case, you didn't have any historical models, since you didn't have any migrations. Django was not able to detect any changes in your models, even though they were different from your database.
The correct way to make changes to your model is to first run manage.py makemigration <my_app>, and then make the changes to your model, followed by another manage.py makemigrations.
You might not be able to do it via pure django and keep your data. I don't have personal experience with south but there are a lot of mentions if this tool. Just in case if nothing else works for you...
Here is what I did to make things work, but there must be a better way so please add more answers/comments...
I deleted the sqlite db and the migration folder
I made the desired changes to model.py
ran syncdb
ran loaddata to load the json data dump that I had saved previously.
just started the dev server

Django 1.7 on Heroku: how do I get makemigrations to rescan the database?

I have Django 1.7 running on Heroku. I've made a change to the models.py file (added a column to a table) but Django doesn't seem to be able to detect this. When I run
python manage.py makemigrations appname
it responds No changes detected in app.
I've tried deleting the appname/migrations folder, but that doesn't help.
Is there a way to get Django to rescan the database and check for differences? This was easy with South.
https://docs.djangoproject.com/en/1.7/topics/migrations/#the-commands
Have you tried
python manage.py migrate
It seems the migrate is "responsible for applying migrations, as well as unapplying and listing their status."