I'm trying to setup a Django project and am faced with the following error:
WARNINGS:
?: (rest_framework.W001) You have specified a default PAGE_SIZE pagination rest_framework setting,without specifying also a DEFAULT_PAGINATION_CLASS.
HINT: The default for DEFAULT_PAGINATION_CLASS is None. In previous versions this was PageNumberPagination. If you wish to define PAGE_SIZE globally whilst defining pagination_class on a per-view basis you may silence this check.
Traceback (most recent call last):
File "manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 82, in handle
executor.loader.check_consistent_history(connection)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/db/migrations/loader.py", line 291, in check_consistent_history
connection.alias,
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration events.0001_initial is applied before its dependency commons.0001_initial on database 'default'.
make: *** [migrate] Error 1
I am running this from within a virtual environment, and have a docker-compose container for a postgres db running. Not sure how to start debugging this or why its happening. Any help would be appreciated
As per your snapshot:
you need to run command:- python manage.py migrate commons and then migrate for events model.
Follow these steps in your migrations folder inside the project:
Delete the pycache and the 0001_initial files.
Delete the db.sqlite3 from the root directory (be careful all your data will go away).
on the terminal run:
python manage.py makemigrations
python manage.py migrate
Note: don't forget to take a backup of your data.
For more detail, you can follow the link
Related
I am attempting to migrate my changes with command
python manage.py migrate
I have already ran the command,
python manage.py makemigrations accounts
which successfully returns,
Migrations for 'accounts':
accounts/migrations/0001_initial.py
- Create model CustomUser
Then in attempting to run python manage.py migrate I recieve this error...
Traceback (most recent call last):
File "/home/mycroft/C/news/manage.py", line 22, in <module>
main()
File "/home/mycroft/C/news/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 95, in handle
executor.loader.check_consistent_history(connection)
File "/home/mycroft/.local/share/virtualenvs/news-ToLZWqxe/lib/python3.9/site-packages/django/db/migrations/loader.py", line 302, in check_consistent_history
raise InconsistentMigrationHistory(
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency accounts.0001_initial on database 'default'.
I am very new to django and can't seem to figure out just what I am doing wrong. Any help would be greatly appreciated!
Maybe you made some changes to you models.py file and these changes aren't sitting well with the inital db structure. If you can track and undo the recent changes it may help, else you'll have to drop your database, delete all migration files your account app. Then repeat the makemigration, migrate, and createsuperuser processes.
Traceback :
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "D:\Anaconda\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "D:\Anaconda\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Anaconda\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Anaconda\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "D:\Anaconda\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "D:\Anaconda\lib\site-packages\django\core\management\commands\makemigrations.py", line 87, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "D:\Anaconda\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "D:\Anaconda\lib\site-packages\django\db\migrations\loader.py", line 274, in build_graph
raise exc
File "D:\Anaconda\lib\site-packages\django\db\migrations\loader.py", line 248, in build_graph
self.graph.validate_consistency()
File "D:\Anaconda\lib\site-packages\django\db\migrations\graph.py", line 195, in validate_consistency
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "D:\Anaconda\lib\site-packages\django\db\migrations\graph.py", line 195, in <listcomp>
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "D:\Anaconda\lib\site-packages\django\db\migrations\graph.py", line 58, in raise_error
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration auth.0012_user_following dependencies reference nonexistent parent node ('account', '0002_contact')
pip freeze txt file link:
https://github.com/shyamparmar29/pip-freeze/blob/master/freeze.docx
There's no app named account in my project but i am still getting this error. I have tried to delete all pycache and migration files but it is not helping.
I even tried to run the project in a virtual environment but i am still getting this error.
Please help.
do these steps:
1- delete migrations folder in each app
2- delete database tables or simply delete it completely
3- run ./manage.py makemigrations appname for each app
4- run ./manage.py migrate
5- finally run the server and see what happens
if it does not work again see this.
edit:
delete your DB and run
python manage.py migrate --fake auth zero
then make migrations again.
You can try the following specific operations as follows:
Delete through the query path under the local python3.8 file:
https://i.stack.imgur.com/FMe2r.png ( reference )
Delete the migration file that is determined to be wrong, here is the last file starting with 0012.
Re-execute python3 manage.py makemigrations after deleting
Execute python3 manage.py migrate
At this point, the migration operation should be normal.
Note: You can also search and delete through the library under the pycharm project, the path is the same as above. It is easy to find and operate.
Scenario:
I am using the simple_history package in Django.
In the documentation, in advanced usage part the "History for a Third-Party Model" it says,
" To track history for a model you didn’t create, use the simple_history.register utility. You can use this to track models from third-party apps you don’t have control over. Here’s an example of using simple_history.register to history-track the User model from the django.contrib.auth app"
So I put that code in the models.py (and tried admin.py too) as below:
from simple_history import register
from django.contrib.auth.models import User
register(User)
Problem:
When I run python manage.py makemigrations it gives the following error:
E:! Project\CMIT\CMITv0101\cmit001>python manage.py makemigrations
Migrations for 'auth':
C:\Program Files\Python36\lib\site-packages\django\contrib\auth\migrations\0009_historicaluser.py
- Create model HistoricalUser
Traceback (most recent call last):
File "manage.py", line 22, in
execute_from_command_line(sys.argv)
File "C:\Program Files\Python36\lib\site-packages\django\core\management_init_.py", line 363, in execute_from_command_line
utility.execute()
File "C:\Program Files\Python36\lib\site-packages\django\core\management_init_.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Program Files\Python36\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Program Files\Python36\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Program Files\Python36\lib\site-packages\django\core\management\commands\makemigrations.py", line 193, in handle
self.write_migration_files(changes)
File "C:\Program Files\Python36\lib\site-packages\django\core\management\commands\makemigrations.py", line 232, in write_migration_files
with io.open(writer.path, "w", encoding='utf-8') as fh:
PermissionError: [Errno 13] Permission denied: 'C:\Program Files\Python36\lib\site-packages\django\contrib\auth\migrations\0009_histo
ricaluser.py'
What can I do now to register my User model?
As per the error description, you do not have permission to make changes in the folder C:\Program Files\Python36\lib\site-packages\django\contrib\auth\migrations
Change the permission of the folder to read, write and execute. Once done, runpython manage.py makemigrations
Also, you are trying to make migrations in system packages. You can create custom User model in a separate app and then make migrations there.
I get this exception:
myproject#aptguettler:~$ manage.py migrate
Traceback (most recent call last):
File "/home/myproject/src/djangotools/djangotools/bin/manage.py", line 32, in <module>
main()
File "/home/myproject/src/djangotools/djangotools/bin/manage.py", line 29, in main
execute_from_command_line()
File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 86, in handle
executor.loader.check_consistent_history(connection)
File "/home/myproject/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 292, in check_consistent_history
connection.alias,
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration myapp.0029_bar is applied before its dependency myapp.0005_foo_squashed_0028_dynamic_year on database 'default'.
My migrations:
name
-------------------------------------------
0001_initial
0002_...
0003_...
0004_...
0005_foo
0006_...
0007_...
...
0028_dynamic_year
0029_bar
0030_...
What could be the reason?
I found the reason with the help of a team mate.
He did this:
squashed migrations
Production deployment and makemigrations
Deleted the squashed python files in the migration directory
I updated the git repo in my (old) develoment system. Then make migrations raised above exception.
Django can't solve this, since some migrations were applied and some not and the old squashed migration files are not available any more.
I took the most simple solution: I dropped my development database and created it from scratch.
I am trying to deploy Django following this tutorial but am getting an error. When the tutorial says to run python manage.py collectstatic, instead of collectstatic running without further prompt as suggested, I get the following:
/home/elections/venv/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
You have requested to collect static files at the destination
location as specified in your settings.
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
I entered Yes and got the following error:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/elections/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/elections/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/elections/venv/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/elections/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/elections/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
collected = self.collect()
File "/home/elections/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
handler(path, prefixed_path, storage)
File "/home/elections/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 354, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "/home/elections/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 260, in delete_file
if self.storage.exists(prefixed_path):
File "/home/elections/venv/lib/python3.6/site-packages/django/core/files/storage.py", line 392, in exists
return os.path.exists(self.path(name))
File "/home/elections/venv/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 50, in path
raise ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
What could have made this happen differently from the tutorial, and how do I fix this error?
As already mentioned you need to define the STATIC_ROOT variable in your settings.py in order to make collectstatic work.
The absolute path to the directory where collectstatic will collect
static files for deployment.
Example: "/var/www/example.com/static/"
You may want to define STATICFILES_DIRS too.
The nginx.conf from the tutorial you have posted expects to serve your collected static files from /home/boards/staticfiles/. Since the tutorial deploys everything on a single, monolithic server which hosts the database (postgres), web server (nginx) and the application (django) you can set it as follows:
STATIC_ROOT = '/home/boards/staticfiles/'