Recently I'm doing a small Django project that I have to work with my teammates,
so I clone the project's repository from github.
The problem is , the database in my computer doesn't have the table so i think i have to makemigrations and migrate it. But after i did that,django only createed its own tables but didn't create other tables that my teammates wrote in Django's models.
I really need your guys hlep
this are the models my teammates wrote
but after i makemigrations and migrate it ,phpmyadmin does not show the tables i want
makemigrations and migrate
the picture on phpmyadmin after I migrate django models
This is my settings
after tried this,it still not working
migrations folder
You should use managed=True in all models for managing the migrations via django
run
python manage.py makemigrations *name_of_you_app_that_has_models_here*
python manage.py migrate *name_of_you_app_that_has_models_here*
Related
I've got a Django application which has been happily humming along now for quite some time (2 years or so).
It's on 3.0.10 currently - when I tried to upgrade to 3.1.3, it says there was a migration for the auth application. No worries! Never been an issue before...
I ran python manage.py migrate and got the following error:
"Cannot find the object "auth_user" because it does not exist or you do not have permissions."
Which, I suppose would be true because we do not have a User model at all in this application. There is no auth_user table, that is correct. In other apps we have an AbstractUser that routes to a table named: org_user - but again:
this particular app (and project) do not have any User model associated with them
Obviously this (apparently, now) leads to some issues.
Any thoughts on how to get around this? I thought about removing auth from installed apps and tried that but it led to more issues when trying to runserver.
You can fake a migration using --fake option:
python manage.py migrate --fake auth
python manage.py migrate
But I suspect the error you get could be symptomatic of a project design issue, such as not setting properly settings.AUTH_USER_MODEL
Solution 1 :- Run these commands :-
python manage.py migrate auth
python manage.py migrate
Solution 2 :- Try to copy your Project in another folder and then run migrations.
I was working on models in django and after creating classes for models and when migrating them I was supposed to use three commands for completing migration of models. The commands are :python manage.py migrate,python manage.py makemigrations <app_name>,python manage.py migrate
So my question is that why should we use three commands like this ?
From the django docs,
migrate: which is responsible for applying and unapplying migrations.
makemigrations: which is responsible for creating new
migrations based on the changes you have made to your models.
If you make changes to your model use python manage.py makemigrations followed by python manage.py migrate.
Incase of initial migration just after you create an app you dont need to python manage.py makemigrations but just python manage.py migrate works.
I had a app where there were models and that site I have deployed. Now I have added 2 models in the app. Unfortunately my migration was deleted in local and after adding the models I again generated the migration with 2 new models.
It gives me 0001_initial.py where I can see my new models too. Now I updated my this file in server. But when I did python manage.py migrate it says "Some of your model has been changed but not reflected so do manage.py makemigrations and manage.py migrate"
I tried "python manage.py migrate" but it says same thing. I am unable to get these models. I have even tried "python manage.py syncdb" but same error.
I have registered these models in admin so in admin I am seeing these models but when I click it my servers get hang. I think because my models are not synchronised or my new tables are not created.
In my migration i can see the new models too but when I do "manage.py migrate" i get errors that I should migrate first and re-migrate.
Is there anyway so that I can compel my app to use that migration forcefully where I have my new models too.
I am trying this from hours but no solution. Need help
Take a look at this:
$ pypy ./manage.py syncdb
/usr/lib64/pypy-2.4.0/site-packages/django/core/management/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command will be removed in Django 1.9
warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
(cut)
I ran a quick google search, but could not find the answer - what should I be using instead of syncdb?
syncdb is deprecated because of the migration system, introduced with django 1.7.
Now you can track your changes using makemigrations. This transforms your model changes into python code to make them deployable to another databases. When you have further modifications you need applied to the database, you can use data migrations.
After you created the migrations you have to apply them: migrate.
So instead of using syncdb you should use makemigrations and then migrate.
Workflow on development after you changed something in your models:
./manage.py makemigrations
./manage.py migrate
And on your production system:
./manage.py migrate
Bonus: you do not need to run migrate for each change. If you have multiple changes not applied yet django will run them in the correct order for you.
You should definitely use migration system. Which lets you track changes in your models.py, and create migrations for the database. The migration system uses the commands makemigrations to create migrations and migrate to migrate the database.
If for whatever reason you need to create a database the same way syncdb did it there is command flag that causes migrate to work the same way. You should only do this if you REALLY need it and you know what you are doing. For example to create an empty database on for a continuous integration system of your choice.
python manage.py migrate auth
# performs migrations for auth and contenttypes contrib apps
python manage.py migrate --run-syncdb
# creates the rest of the database
Tested on Django 1.9.1.
You should use the makemigrations and migrate commands that were introduced in django 1.7
https://docs.djangoproject.com/en/1.7/topics/migrations/
syncdb has some problem with db migration. so, after django 1.7 makemigrations and migrate have been introduced.
Now in django 1.9 syncdb has been deprecated.
try
1. python manage.py makemigrations which detects changes in db and creates one .py file as inside migrations folder
2. python manage.py migrate will apply the migrations to the database
I have a django database with a custom user profile for the user model.
The problem is that when I want to add new fields to my userprofile class, I get the error no such column, regarding the new field, when trying to access the users table.
Any way then to update the userprofile model without having to rebuild the database?
Thank you.
Here is how to do it..
First install south
pip install south
Then add to your settings INSTALLED_APP list as -
...,
'south',
...
What is south?.. Well south is a django app that helps you updating your database without having to rebuild it. Now initialise your models with-
python manage.py syncdb // this will create the south tables for migrations
python manage.py schemamigration <appname> --initial // (once per app) this will create the initial model files in a migrations package
python manage.py migrate
Then every time you update your models just need to perform an update with -
python manage.py schemamigration <appname> --auto
python manage.py migrate <appname>
You can find the full documentation here - http://south.readthedocs.org/en/latest/tutorial/