I have created a custom User model in Django. Now, I want to run my application on heroku. But I can't run migrate, code error:
ValueError: Dependency on app with no migrations
How can I solve this problem?
Full message error
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 83, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 52, in __init__
self.build_graph()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 223, in build_graph
self.add_external_dependencies(key, migration)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 188, in add_external_dependencies
parent = self.check_key(parent, key[0])
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 169, in check_key
raise ValueError("Dependency on app with no migrations: %s" % key[0])
ValueError: Dependency on app with no migrations: main_site
I have made migrations locally and add "0001_initial.py" file to git.
Now it works fine.
Related
Had an issue with django migration files not syncing with the db (was getting column not found) due to a Model being renamed. I don't completely understand migrations but after following different stackoverflow answers - performing fake zero migrations and then adding the manual migration file:
# Generated by Django 4.1 on 2022-10-10 00:47
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('campaigns', '0015_blah_blah'),
]
operations = [
migrations.RenameModel("PreviousModelName", "ModelName")
]
I thought the issue had been fixed. I can query the database without errors, I can add new fields to the renamed model and migrate them. Everything seemed to be working. But now I've realised that when I run python manage.py test I get the following error:
Traceback (most recent call last):
File "/code/manage.py", line 25, in <module>
main()
File "/code/manage.py", line 21, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/test.py", line 24, in run_from_argv
super().run_from_argv(argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/test.py", line 68, in handle
failures = test_runner.run_tests(test_labels)
File "/usr/local/lib/python3.9/site-packages/django/test/runner.py", line 1045, in run_tests
old_config = self.setup_databases(
File "/usr/local/lib/python3.9/site-packages/django/test/runner.py", line 941, in setup_databases
return _setup_databases(
File "/usr/local/lib/python3.9/site-packages/django/test/utils.py", line 220, in setup_databases
connection.creation.create_test_db(
File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/creation.py", line 78, in create_test_db
call_command(
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 198, in call_command
return command.execute(*args, **defaults)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 96, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 349, in handle
post_migrate_state = executor.migrate(
File "/usr/local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 135, in migrate
state = self._migrate_all_forwards(
File "/usr/local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
state = self.apply_migration(
File "/usr/local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python3.9/site-packages/django/db/migrations/migration.py", line 130, in apply
operation.database_forwards(
File "/usr/local/lib/python3.9/site-packages/django/db/migrations/operations/models.py", line 96, in database_forwards
schema_editor.create_model(model)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 442, in create_model
sql, params = self.table_sql(model)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 216, in table_sql
definition, extra_params = self.column_sql(model, field)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 346, in column_sql
field_db_params = field.db_parameters(connection=self.connection)
File "/usr/local/lib/python3.9/site-packages/django/db/models/fields/related.py", line 1183, in db_parameters
target_db_parameters = self.target_field.db_parameters(connection)
File "/usr/local/lib/python3.9/site-packages/django/db/models/fields/related.py", line 1060, in target_field
return self.foreign_related_fields[0]
File "/usr/local/lib/python3.9/site-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.9/site-packages/django/db/models/fields/related.py", line 747, in foreign_related_fields
rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field
File "/usr/local/lib/python3.9/site-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.9/site-packages/django/db/models/fields/related.py", line 734, in related_fields
return self.resolve_related_fields()
File "/usr/local/lib/python3.9/site-packages/django/db/models/fields/related.py", line 1103, in resolve_related_fields
related_fields = super().resolve_related_fields()
File "/usr/local/lib/python3.9/site-packages/django/db/models/fields/related.py", line 712, in resolve_related_fields
raise ValueError(
ValueError: Related model 'app.modelname' cannot be resolved
It seems like it throws an error when trying to create the test database. Is there something I need to do to sync the test database?
First delete all migration files and migrate apps manually by doing below command:
python manage.py makemigrations appname
python manage.py sqlmigrate appname 0001 #This value will generate after makemigration.
python manage.py migrate
Hope this will solve your error.
I deleted some migration files that were giving me the error.
Then when I write "python3 manage.py showmigrations" I get the following error:
root#chat-manager:/var/www/jinabot# python3 manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 23, in <module>
main()
File "manage.py", line 19, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.7/dist-packages/django/core/management/__init__.py", line 419, in exe
utility.execute()
File "/usr/local/lib/python3.7/dist-packages/django/core/management/__init__.py", line 413, in exe
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.7/dist-packages/django/core/management/base.py", line 354, in run_fro
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.7/dist-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.7/dist-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/django/core/management/commands/makemigrations.py", l
loader = MigrationLoader(None, ignore_no_migrations=True)
File "/usr/local/lib/python3.7/dist-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/usr/local/lib/python3.7/dist-packages/django/db/migrations/loader.py", line 259, in build_g
self.graph.validate_consistency()
File "/usr/local/lib/python3.7/dist-packages/django/db/migrations/graph.py", line 195, in validate
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/usr/local/lib/python3.7/dist-packages/django/db/migrations/graph.py", line 195, in <listcom
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/usr/local/lib/python3.7/dist-packages/django/db/migrations/graph.py", line 58, in raise_err
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration app.0172_auto_20220603_1746 dependencie
_auto_20220601_2313')
How to fix it?
If you have such an error at the development stage, then I don’t know if this is correct, but I would probably delete all the migrations of the conflicting application and the database too, and then run "python manage.py makemigrations"
(Sorry, comments are not available to me)
I'm new to the Django framework and just trying to create a basic website, but when I try to open the server with the python manage.py runserver I get this error:
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 "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 601, in run_with_reloader
exit_code = restart_with_reloader()
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 230, in restart_with_reloader
p = subprocess.run(args, env=new_environ, close_fds=False)
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\site-packages\run\__init__.py", line 145, in __new__
process = cls.create_process(command, stdin, cwd=cwd, env=env, shell=shell)
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\site-packages\run\__init__.py", line 121, in create_process
shlex.split(command),
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\shlex.py", line 310, in split
return list(lex)
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\shlex.py", line 299, in __next__
token = self.get_token()
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\shlex.py", line 109, in get_token
raw = self.read_token()
File "C:\Users\siuba\AppData\Local\Programs\Python\Python37\lib\shlex.py", line 140, in read_token
nextchar = self.instream.read(1)
AttributeError: 'list' object has no attribute 'read'
Does anyone know the answer? If so please help!
Thanks
Are you following a tutorial? If so, please share it with us. There may be a problem with your python installation. Please delete all python installations on your computer and install the latest version. Then create django project again.
I already have an application using PostgreSQL as db. I want to build a service using Django. Tried "inspectdb"... but it is giving an expection:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/inspectdb.py", line 25, in handle
for line in self.handle_inspection(options):
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/inspectdb.py", line 70, in handle_inspection
constraints = connection.introspection.get_constraints(cursor, table_name)
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql/introspection.py", line 172, in get_constraints
"foreign_key": tuple(used_cols[0].split(".", 1)) if kind.lower() == "foreign key" else None,
IndexError: list index out of range
Figured out the issue.
Apparently, the db user didn't have sufficient permissions.
I have a local python environment working, but when I try and load in initial data.
python manage.py loaddata initial_data.json
I get an error about "RemovedInDjango18Warning"?
I am not a python dev to say - so this error is new to me.
C:\Python27\aasoo>python manage.py loaddata initial_data.json
C:\Python27\lib\site-packages\djorm_pgfulltext\models.py:323: RemovedInDjango18Warning: `SearchManagerMixIn.get_query_set` method should be renamed `get_queryset`.
class SearchManager(SearchManagerMixIn, models.Manager):
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 338, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\modeltranslation\management\commands\loaddata.py", line 50, in handle
return super(Command, self).handle(*fixture_labels, **options)
File "C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py", line 61, in handle
self.loaddata(fixture_labels)
File "C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py", line 91, in loaddata
self.load_label(fixture_label)
File "C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py", line 142, in load_label
for obj in objects:
File "C:\Python27\lib\site-packages\django\core\serializers\json.py", line 81, in Deserializer
six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])
File "C:\Python27\lib\site-packages\django\core\serializers\json.py", line 75, in Deserializer
for obj in PythonDeserializer(objects, **options):
File "C:\Python27\lib\site-packages\django\core\serializers\python.py", line 122, in Deserializer
m2m_data[field.name] = [m2m_convert(pk) for pk in field_value]
django.core.serializers.base.DeserializationError: Problem installing fixture 'C:\Python27\aasoo\content\fixtures\initial_data.json': 'int' object is not iterable
C:\Python27\aasoo>
You should rename get_query_set to get_queryset in SearchManagerMixIn. Can you paste the definition of the class if you need more help.