HOW TO WORK ON SQLITE DATABASE IN DJANGO? - django

I am new to programming i am trying to add product through my admin panel but i am getting this error:
no such table found
[I am using python version 3.8.2
Django version==3.0.7
and i am getting this error: No such table found][1]
thanks for help
[1]: https://i.stack.imgur.com/ayhGa.png

you can inspect the created databses with the DB Browser for SQLite.
Did you run python manage.py makemigrations and python manage.py migrate after you editied or created a model?
Also be sure, to include any new app in the installed_app list in the settings.py of your project.

Related

Import SQL file in Django (v-2.2)

I have a Django project and I am using MySQL as default. I already have created and migrated 2 models. Now I have a SQL file. I want to create new models and populate those models with this SQL file. I am using Windows 10.
I have searched this query but did not get working solution.
I think you are looking for inspectdb. Try Integrating Django with a legacy database.
First of all create a database using your SQL file.
Then add the details of your database into settings.py file.
Just run python manage.py inspectdb command, you will see all the table structures in your new database which creates with your SQL file as a Django Models structure. (convert your database into python django model).
You can get those details as a .py by running python manage.py inspectdb > models_new.py command.
Now you have all the table structures in that models.py file which create in last step.
Then change your settings.py file for old database which you migrated earlier.
Get those details from models_new.py and add into your app_name/models.py file and save it.
Run python manage.py makemigrations and python manage.py migrate.
I found useful video tutorial which is not in English, but you can get an idea about your question how to do it.

Unable to get all the fields of a model when we alter the table manually

I'm new django web framework. I have a models.py file where i given information about my entity fields, i ran the manage.py migrate command table generated i have alter the table manually without touch the models.py later I have run the python manage.py inspectdb > myapp/models.py in controller level using os.system models.py updated then i have tried models.objects.all() I'm unable to get the newly added field, I have called the view By using ajax call , after page refresh only new field name coming.
can you help how to get all field names with in the ajax response only with out page refresh. It would be grateful if you can help me
Note: I have checked in view level only with out page refresh first time only new column not came after page refresh it came
Thanks in advance...
I'm looking for cache in django
Before migrating, you need to create migrations.
If your DB is correctly configured, here you are (python3/python depending on version that you are using):
First: python3 manage.py makemigrations
Second: python3 manage.py migrate
makemigrations creates SQL queries, and migrate runs it. You can read more here: Django 1.8 - what's the difference between migrate and makemigrations?

Reset Django registration models?

I am trying to implement django registration-redux 1.2. I installed the application and added to it settings.py of my project. I ran manage.py syncdb as well as makemigrations/migrate. Typing these commands again and I get no changes detected. However it seems like the tables are not getting created. When I try to register I get the following error:
ProgrammingError at /main/register/ (1146, "Table 'la_test_serve.registration_registrationprofile' doesn't exist")
Is there a way to reset the project/app so that these tables get created?
Thanks,
Robert
Try to run schemamigration for your registration apps
python manage.py schemamigration registration --initial
after that run migrate
python manage.py migrate registration
Remove the app from your "INSTALLED APPS" setting. Then run manage.py makemigrations and manage.py migrate. Reinstall the app.
Note: If you didn't add 'registration' (yes, simply 'registration') to your "INSTALLED APPS", it won't work.
I found this error occurred when I was reinstalling django-registration-redux.
Either way, check that you have deleted not only the table for registration in the database but also ensure that in the migrations table delete the corresponding row, in this case 'registration'.

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."