18👍
There is no syntax. Django doesn’t removes tables or columns. You have to manually change your database or use a migration tool like South.
If you justing playing around with tutorial the easier way is to delete your sqlite database file and run a sync again.
30👍
If you don’t want to delete and re-sync your current database, the best way is to drop the table from your model manually:
$ python manage.py dbshell
> (Inside the DB shell)
> DROP TABLE {app-name}_{model-name};
- [Django]-How to check if an element is present in a Django queryset?
- [Django]-Combining Django F, Value and a dict to annotate a queryset
- [Django]-What is the equivalent of "none" in django templates?
21👍
Why not simply try deleting the models from your models.py file? When you run
python manage.py makemigrations
the migrations file should be updated with the deleted models.
- [Django]-Annotate a sum of two fields multiplied
- [Django]-ValueError: Cannot add *: instance is on database "default", value is on database "None"
- [Django]-Django Rest Framework Postman Token Authentication
4👍
The most easiest solution is to just delete your model from models.py and run
python3 manage.py makemigrations
(Note: Remove the model from everywhere where you have imported it like admin.py, views.py, or any other file where you have imported it)
- [Django]-Django: How to filter Users that belong to a specific group
- [Django]-Extending Django Admin Templates – altering change list
- [Django]-Unique model field in Django and case sensitivity (postgres)
3👍
Commenting out the class that defines the model did it for me. Once I had done it and ran python manage.py makemigrations
,
I got this as response:
- Delete model MyModel
.
Checked afterwards with a DB Browser and it was actually removed.
- [Django]-Celery discover tasks in files with other filenames
- [Django]-Generics vs viewset in django rest framework, how to prefer which one to use?
- [Django]-What's the best option to process credit card payments in Django?
1👍
If you are facing issue to update changes onto DB so you can directly run this command.
python manage.py migrate --run-syncdb
- [Django]-Django, save ModelForm
- [Django]-Why is my static CSS not working in Django?
- [Django]-Django – Where are the params stored on a PUT/DELETE request?
1👍
I found a simpler method, by sheer experimentation. Even after deleting tables, Django was not making the migrations, so I did the following:
Simply delete the files created in your myapp->migrations directory, making sure that you do not delete the init.py and pycache
-
Starting from 001initial.py and downwards delete the files.
-
Run python manage.py makemigrations
-
Run python manage.py migrate
-M
- [Django]-Aggregate (and other annotated) fields in Django Rest Framework serializers
- [Django]-Django error: relation "users_user" does not exist
- [Django]-How to set environment variables in PyCharm?
0👍
Django’s database handling through syncdb
is purely additive: any new models will be added, but deleted models will not be deleted and modified models will not be modified.
If you do not have any data you want to preserve, you are fine just dropping and recreating the database: if you have anything you want to preserve, or even if you intend to have anything you want to preserve, I cannot advise you strongly enough to use a migration tool: South has been the de facto standard for every project I’ve worked on.
- [Django]-Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually
- [Django]-Heroku, postgreSQL, django, comments, tastypie: No operator matches the given name and argument type(s). You might need to add explicit type casts
- [Django]-Manipulating Data in Django's Admin Panel on Save
0👍
Since the Migration command handle Model(database) you can do following steps.
First type
python manage.py makemigrations app_name # it will restructure your model
then type
python manage.py migrate app_name # it will apply to restructure your database.
Example:
I had Posts and PostDetail model,
later on, I wanted to remove PostDetail model and some fields(columns) from Posts model too.
I simply run migrations and migrate commands,checked in Mysql Database. It worked fine.
Hope it will work for you too.
- [Django]-Django pass object to include
- [Django]-Django ManyToMany model validation
- [Django]-Performing a getattr() style lookup in a django template
0👍
Weather you’re removing a single model or a full app, you should first
remove the desired models from the models.py file.Moreover, you have to make sure that no other file imports these
models or uses them (admin.py, views.py, etc).Next, run South or migrate your database to properly delete these
models from your database.
Check the source of this information on the link below:
http://www.marinamele.com/how-to-correctly-remove-a-model-or-app-in-django
- [Django]-Django migrate –fake and –fake-initial explained
- [Django]-TypeError: ManyRelatedManager object is not iterable
- [Django]-Why does Django's render() function need the "request" argument?
0👍
- Comment out the class you want to delete in
models.py
. - Comment out any other references to the model e.g. in
admin.py
. - Run the following commands in terminal:
-
python manage.py makemigrations <your_app>
-
python manage.py migrate
-
This should remove the related table from the database.
- [Django]-Redirect on admin Save
- [Django]-Is Django for the frontend or backend?
- [Django]-How to get all users of a group in Django?