I cannot "makemigrations" in my Django project. When I try to do
"python manage.py makemigrations"
It shows the following
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/commands/makemigrations.py", line 89, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/loader.py", line 273, in build_graph
raise exc
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/loader.py", line 247, in build_graph
self.graph.validate_consistency()
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/graph.py", line 243, in validate_consistency
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/graph.py", line 243, in <listcomp>
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/graph.py", line 96, in raise_error
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration djoser.0001_initial dependencies reference nonexistent parent node ('auth', '0011_update_proxy_permissions')
I tried installing mysqlclient and creating the database all over again but then it doesn't work at all.
Your migrations directory is broken. Django creates migrations files for each migration (each time you type makemigration.
Currently, one of your migrations file has something like:
dependencies = [
('accounts', '0011_update_proxy_permissions'),
]
And migrations/0011_update_proxy_permissions.py doesn't exist. You need either edit this migration manually or remove everything in migrations directory and run makemigrations from scratch. If you remove migrations you will also need to drop the database so django would create it from the scratch.
There're a lot of articles out there that would help you to investigate your issue further. Like this one
Related
I made a completely new project using the django-admin startproject and I also made an app using django-admin startapp and I am able to apply the initial migrations but not able to do the migrate. and I didn't add any code into the project. It's completely a new project.
python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying auth.0013_user_following...Traceback (most recent call last):
File "G:\My Drive\Django 4 by example\myshop\manage.py", line 22, in <module>
main()
File "G:\My Drive\Django 4 by example\myshop\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 448, in execute
output = self.handle(*args, **options)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 96, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\commands\migrate.py", line 349, in handle
post_migrate_state = executor.migrate(
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\migrations\executor.py", line 135, in migrate
state = self._migrate_all_forwards(
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\migrations\executor.py", line 167, in _migrate_all_forwards
state = self.apply_migration(
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\migrations\executor.py", line 252, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\migrations\migration.py", line 130, in apply
operation.database_forwards(
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\migrations\operations\fields.py", line 108, in database_forwards
schema_editor.add_field(
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\sqlite3\schema.py", line 383, in add_field
if field.many_to_many and field.remote_field.through._meta.auto_created:
AttributeError: 'str' object has no attribute '_meta'
I uninstalled all the packages which I installed for the project, uninstalled Django as well, and deleted all the migrations of all the projects but still it's not working.
I'm trying to deploy my app on PythonAnywhere and when i go to apply the migrations i get an error that a migration dependency does not exist.
I've completely reset the migrations by deleting them from the migrations folder, dropping the database and re-creating it, and running makemigrations.
I only have my one initial migration now and everything works on my local machine.
workflow goes like this:
1 - clone the current version I'm using to PythonAnywhere.
2 - run ./manage migrate to initialize the database (the very first time) and get error:
(rwe) 17:00 ~/rwe (develop)$ ./manage.py migrate
asyncio DEBUG Using selector: EpollSelector
Traceback (most recent call last):
File "./manage.py", line 21, in <module>
main()
File "./manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 86, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/db/migrations/loader.py", line 274, in build_graph
raise exc
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/site-packages/django/db/migrations/loader.py", line 248, in build_graph
self.graph.validate_consistency()
File "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/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 "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/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 "/home/IAMCB/.virtualenvs/rwe-Cn2YEGYr/lib/python3.7/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 backend.0001_initial dependencies reference nonexistent parent node ('auth', '0013_delete_users')
(rwe) 17:12 ~/rwe (develop)$
The website loads, and I can browse, etc.. I just can't use anything that relies on the database considering the initial migration hasn't been applied.
The only real change between the systems is the secret key is different for production and DEBUG=False
I figured it out.
I updated django from 2.2.3 to 3.0.3 and the migrations I am missing must have generated during my use of 2.2.3.
worked for me but not for my PythonAnywhere server. I've recreated my virtualenv on my dev machine and reset all my migrations. Everything is now matching up without issue.
I'm developing a project with Django CMS 3.5. I used SQLite for development and have data in there. Now I'm trying to migrate to PostgreSQL. My steps so far:
python manage.py dumpdata --natural-primary --natural-foreign > dump.json
Switching to production settings
python manage.py migrate
TRUNCATE django_content_type CASCADE;
python manage.py loaddata dump.json
But I encounter the next error:
Traceback (most recent call last):
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 178, in __get__
rel_obj = getattr(instance, self.cache_name)
AttributeError: 'Page' object has no attribute '_node_cache'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/webmaster/tc56/env/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/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 69, in handle
self.loaddata(fixture_labels)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 109, in loaddata
self.load_label(fixture_label)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 175, in load_label
obj.save(using=self.using)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/serializers/base.py", line 205, in save
models.Model.save_base(self.object, using=using, raw=True, **kwargs)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/base.py", line 833, in save_base
update_fields=update_fields,
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in send
for receiver in self._live_receivers(sender)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in <listcomp>
for receiver in self._live_receivers(sender)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/cms/signals/page.py", line 8, in pre_save_page
instance.clear_cache(menu=True)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/cms/models/pagemodel.py", line 963, in clear_cache
menu_pool.clear(site_id=self.node.site_id)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 184, in __get__
rel_obj = self.get_object(instance)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 159, in get_object
return qs.get(self.field.get_reverse_related_filter(instance))
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/query.py", line 380, in get
self.model._meta.object_name
cms.models.pagemodel.DoesNotExist: Problem installing fixture '/home/webmaster/tc56/dump.json': TreeNode matching query does not exist.
This was fixed a few days ago.
Will land with django CMS 3.5.3
$ python manage.py test homepage.shortlistedlist
When i run above django rest framework testcase file, i met below error, kindly help me to solve this problem,
(py3.4)testuser#testuser-To:~/projects/testfile/testfile$ python manage.py test homepage.compareproperties --settings=testfile.settings.test
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/test/runner.py", line 146, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/test/runner.py", line 95, in build_suite
tests = self.test_loader.discover(start_dir=label, **kwargs)
File "/usr/lib/python3.4/unittest/loader.py", line 255, in discover
self._get_directory_containing_module(top_part)
File "/usr/lib/python3.4/unittest/loader.py", line 269, in _get_directory_containing_module
full_path = os.path.abspath(module.__file__)
AttributeError: 'module' object has no attribute '__file__'
Thanks In Advance,
I was able to solve this by adding an empty __init__.py to the root of my project.
I think the clue is the get_directory_containing_module() call - without __init__.py, it doesn't see the directory as a module.
I am getting an error trying to apply a first South migration. I have tried various suggestions (like removing .pyc files in the migrations folder, converting the app as well as trying to start it afresh, other fiddles). Can anyone here suggest what I might do? Thanks
(env)~/code/django/ssc/dev/ssc/ssc> python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/usr/local/lib/python2.7/dist-packages/south/migration/__init__.py", line 166, in migrate_app
Migrations.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 228, in calculate_dependencies
migration.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 362, in calculate_dependencies
for migration in self._get_dependency_objects("depends_on"):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 342, in _get_dependency_objects
for app, name in getattr(self.migration_class(), attrname, []):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 314, in migration_class
return self.migration().Migration
AttributeError: 'module' object has no attribute 'Migration'
(env)~/code/django/ssc/dev/ssc/ssc> python manage.py convert_to_south crewcal
This application is already managed by South.
(env)~/code/django/ssc/dev/ssc/ssc> python manage.py migrateTraceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/usr/local/lib/python2.7/dist-packages/south/migration/__init__.py", line 166, in migrate_app
Migrations.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 228, in calculate_dependencies
migration.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 362, in calculate_dependencies
for migration in self._get_dependency_objects("depends_on"):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 342, in _get_dependency_objects
for app, name in getattr(self.migration_class(), attrname, []):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 314, in migration_class
return self.migration().Migration
AttributeError: 'module' object has no attribute 'Migration'
In my case the AttributeError: 'module' object has no attribute 'Migration' error was simply a matter of having an extra .py file in my migrations folder.
I had an extra utilities module in my migrations directory which caused South to choke. Moving the module into a different directory (above my apps migrations directory) solved the problem for me.
Maybe a bit late, but still...
Is it possible you have any other package (folder with __init__.py) in your migration package and it interferes with the structure?
Wow. I was getting the AttributeError: 'module' object has no attribute 'Migration' error for a completely different reason than the above answers.
I had a migration file which had a bad indent:
class Migration(SchemaMigration):
def forwards(self, orm):
#
def backwards(self, orm):
#
models = {...}
As opposed to ...
class Migration(SchemaMigration):
def forwards(self, orm):
#
def backwards(self, orm):
#
models = {...}
I don't know why I had that but when I fixed that the error was gone.