no such table: Append_employeemodel Django - django

GitHub repository
When I send a post request I get this.
I previously try
python manage.py syncdb
./manage.py migrate
python manage.py migrate
python manage.py createsuperuser
python manage.py makemigrations
python manage.py migrate
but I still got an error. The Git Hub link is above please help me.

Django looks for models in a models.py file or models directory, not 'model.py'.
I'd strongly suggest you use django-admin startproject name [directory] when creating new projects or django-admin startapp name [directory] when creating new apps in order for a consistent directory structure to be generated.
Also try and follow the naming conventions in Django. For example employeeModel could rather be Employee, empName rather employee_name, TradeInfo rather trade_info, etc.

Related

Django.Programming Error: Table Name Does Not Exist - How to solve?

I deleted a model in Django which I created for testing purposed. Now when I try and run makemigrations and mirgrate I get the following error:
django.db.utils.ProgrammingError: table "members_test" does not exist
Is there a standard procedure I should be doing when deleting a model? I only deleteed the code out of my Models file and tried migrating after.
I've only tried runing migrate and make migrations in addtion to scouring the web.
Simply you can delete all migrations folder and re-migrate using below command:
python manage.py makemigrations appname
python manage.py sqlmigrate appname 0001
python manage.py migrate

Django - Make migration command detects changes but on migrating says 'No migrations to apply'

i am new to django developement after making changes to my model i tried to run the command python manage.py makemigrations my_app
it detects changes in my model and shows me the message
todoapp/migrations/0001_initial.py
- Create model confess
- Create model UserChoice
- Create model comment
but on executing python manage.py migrate my_appcommand i've got this message
No migrations to apply.
i usually do this after making changes in models, i don't know what happened now.
plss help me.
Firstly, try
python manage.py makemigrations my_app
python manage.py migrate
If this does not work and the project is still in development:
Delete migrations folder and pycache folder.
Delete db.sqlite3 (your database).
Make and apply migrations again.
I think this will work.
Delete all migrations files and __pychache__except__init__.py from your project and app. Also db.sqlite3 database then rerun makemigrations and migrate commands. It should solve your issue.

Adding new field to existing database table in django python

I have a Postgresql database connected with my django application, Now I have a existing table in the database and want to add a new field to this table using the migrate command. But when I try to add this new field to my models.py and run makemigration and migrate commands, django says there are no new migrations to apply. Can you help me with how to add a new field to existing table.
Try running makemigrations command specifying your app name like this:
python manage.py makemigrations myapp
and then try running migrate command
After a long research I got a solution as below:
pip install django-extensions
and add this in the install app of settings.py
INSTALLED_APPS = [
'django_extensions'
]
Now, run migrations for your installed apps
python manage.py makemigrations your_app_name
python manage.py migrtate your_app_name
Done! See Your Database...

django error OperationalError at /admin/blog/post/

i get this error in simple django programme run..
OperationalError at /admin/blog/post/
no such table: blog_post
if django version >=django 1.7
python manage.py makemigrations
python manage.py migrate
else
python manage.py schemamigrations
python manage.py migrate
so you need to migrate (map the model changes / new models into database tables) the changes so that your page works properly
delete the migrations folder in app and then do :
python manage.py makemigrations
python manage.py migrate
python manage.py migrate --run-syncdb
it worked for me
You need to run migrations before you can do that operation. The necessary tables don't exist in your database (as described by the error).
Check for a typo in the name of your Model. If you change your model name after makemigration and migrate, then it doesn't work and find the correct model name anymore.

DatabaseError: no such column error

So I have a model that I wanted to add ImageField to, so I typed in
picture = models.ImageField(upload_to='media/images')
I then ran syncdb and went into the shell:
python2 manage.py syncdb
python2 manage.py shell
I then imported the model and tried
"model".objects.get(pk=1)
I get the error:
DatabaseError: no such column: people_people.picture
When I run manage.py sql for the model
"picture" varchar(100) NOT NULL
is in the database.
What solutions do you guys have? I can't delete the data in the database.
As noted in the documentation syncdb doesn't add columns to existing tables, it only creates new tables.
I suggest running
python manage.py sqlall <your_app>
Looking at the sql it outputs for the table you're changing, and then running
python manage.py dbshell
in order to manually issue an ALTER TABLE command.
In future, you might like to use a migration tool like South.
There are two possibilities that to get this error 1) You added extra field to model after doing the syncdb. 2) you added new class to model.py file in django.
Solution for this is:
First install south by using command
for windows: **easy_install south** //for that you need to go to the script folder of python folder in c drive.
for linux: **sudo easy_install south**
Then follow the steps which are included here migration tutorials
step1- python manage.py schemamigration your_app_name --initial
step-2 python manage.py migrate your_app_name
Hope this will help you.
As of 1.7 migrations within Django replaces South.
Create a new set of migration instructions by running the following command in terminal:
$ python manage.py makemigrations
Check the output in the migration folder it creates to make sure they make sense then run the following terminal command to complete the migrations:
$ python manage.py migrate
That's it.
Running migrations this way allows others to implement the same migrations instead of having to manually implement db changes on every machine using the code. On the new machine all they have to run is:
$ python manage.py migrate