I have an existing database in Oracle 11.2.
I am trying to use inspectdb utility of django to automatically create the models but I am getting the error:
ORA-00904: "IDENTITY_COLUMN": invalid identifier
There is no column named IDENTITY_COLUMN in any of the tables and since I am not directly accessing the database, the chances of misspelling a column name or accessing a wrong column is not possible.
It would be very helpful if someone can give a direction as to what to fix to solve this error.
I had a similar problem also working with Oracle 11.2
I downgraded Django===2.1 to Django===1.11.13 temporarily to run inspectdb as a work around since my legacy models needed to be manually cleaned up anyway, but it was a good place to start for reverse engineering models from a legacy db.
Same thing happened to me . First downgrade your django into a lower version (1.11.22) and run
python manage.py inspectdb > your_app_name/models.py
Then upgrade to whatever version you are using . I was using 3.0.4
I'm not sure if it is possible.
The docs don't mention Oracle:
inspectdb works with PostgreSQL, MySQL and SQLite.
But a user said they got it working, for example this comment in a previous question. See also this older question for some hints.
Related
I am getting this strange error
ProgrammingError at /save_hsn/
syntax error at or near "ON"
LINE 1: ...021-01-28T06:17:43.784614+00:00'::timestamptz, 1) ON CONFLIC...
this is my views.py part where I am getting the error
user_gst_codes.objects.bulk_create(hsn_list, ignore_conflicts=True)
If I remove ignore_conflicts=True, everything works.
Moreover, I start getting this error after deploying my Django app on cPanel, on localhost this doesn't give any error.
On localhost-
Python 3.6.6, Django 3.1
On cPanel-
Python 3.6.11, Django 3.1
Is this an issue with the Python version?
I am inserting data in bulk and also need to keep the unique check.
Any help would be appreciated.
Notice that the ON CONFLICT clause is only available from PostgreSQL 9.5. If you are using an earlier version, you will need a workaround to have the upsert feature. Please check local postgresql version and server postgresql version.
I have an application in Django 1.6.5. I have a model where I removed one field, I added another field, and the third upgraded. And when we now turn to the model in the admin panel, I get the message:
ProgrammingError at /admin/app/subscription/
column app_subscription.enabled does not exist
The command python manage.py syncdb does not work.
Django (hopefully) doesn't modify your database schema if you don't explicitely ask for it. The syncdb command works perfectly, but (as documented) it will only create tables that don't yet exists (and are not marked as being managed externally in your models).
So you have mostly three options here:
manually drop your table and re-run syncdb. This mean you will loose all our data, so it's hardly a "solution"
manually alter your database schema. You won't loose your data, but you'll have to repeat the same (manual) operation everywhere your app is deployed... If it's only installed on your local workstation that might be ok, else it's not a reliable professional production-level option.
Use South (which seems to be installed since you do have a migrate command available.
Note that solution #3 imply that you do create the migration files for your app, as documented here : http://south.readthedocs.org/en/latest/tutorial/part1.html#the-first-migration
It just happened that I faced the same issue with django 1.9.x, where I added a new field in my django app which triggered the same error as you mentioned above.
I logged into the dbshell environment using
python manage.p dbshell # I know some use ./manage.py
and dropped all of my tables by running the following command within the dbshell to drop the tables
your_psql=# drop schema public cascade;
This will drop all of your tables (be careful as you may lose your data, there away to keep the data!) and you will get a message right after executing this command tells you that all dropped. Right after that run the following command to create the schema again, otherwise your server will not run:
your_psql=# create schema public;
Then just do the
python manage.py makemigrations # you might not need this, and
python manage.py migrate
And you're ready to go.
I know this answer might be very late but I hope it will help someone.
Cheers
I'm not sure if this is an issue specific to sqlite databases but after adding some properties I executed syncdb successfully but still the the columns were not added to the database and when I try the access the model in admin I get no such column error.
Why is this happening and how do I overcome this issue?
Details: Django 1.3, Python 2.6, OSX 10.6, PyCharm.
sync db doesn't make integrate schema changes once the tables are created. You have to delete the database manually and do syncdb again. See the boxed information in this link
http://docs.djangoproject.com/en/dev/ref/django-admin/#syncdb
As always, syncdb does not migrate the existing schema.
I think one can find solution here: A nice blog to start with Django:
Getting Started with Django REST Framework (DRF) and AngularJS :
http://engineroom.trackmaven.com/blog/getting-started-drf-angularjs-part-1/
I got this after installing the tagging application. I've installed it via settings.py as well as placing it on the import path so I think I've done everything right there. This is what turns up. You can see my error log here. I've run syncdb, so my database should be synced up.
Have you checked output of syncdb and actually seen, that table was created? Take a look into your database and check, whether the table is created. If not, run syncdb again and if this doesn't help, create the table by hand (or drop the database and create it again from scratch).
I have recently updated my model, added a BooleanField to it however when I do python manage.py syncdb, it doesn't add the new field to the database for the model. How can I fix this ?
From Django 1.7 onwards
Django has built in support for migrations - take a look at the documentation.
For Django 1.6 and earlier
Django doesn't support migrations out of the box. There is a pluggable app for Django that does exactly that though, and it works great. It's called South.
Django currently does not do this automatically. Your options are:
Drop the table from the database, then recreate it in new form using syncdb.
Print out SQL for the database using python manage.py sql (appname), find the added line for the field and add it manually using alter table SQL command. (This will also allow you to choose values of the field for your current records.)
Use South (per Dominic's answer).
Follow these steps:
Export your data to a fixture using the dumpdata management command
Drop the table
Run syncdb
Reload your data from the fixture using the loaddata management command
As suggested in top answer, I tried using South, and after an hour of frustration with obscure migration errors decided to go with Django Evolution instead.
I think it's easier to get started with than South, and it worked perfectly the first time I typed ./manage.py evolve --hint --execute, so I'm happy with it.
Havent used django in a while, but i seem to remember that syncdb does perform alter commands on db tables. you have to drop the table then run again and it will create again.
edit: sorry does NOT perform alter.
In django 1.6
At first we have run - python manage.py sql <app name>
Then we have to run - python manage.py syncdb
If you run Django with Apache and MySQL, restart apache after making migration with makemigrations.