Python, Django - loaddata issue "RemovedInDjango18Warning" - python

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.

Related

django.db.migrations.exceptions.NodeNotFoundError: Migration app.0172_auto_20220603_1746 dependencie _auto_20220601_2313')

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)

Can't start test server with python django

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.

Upgrading to Django 1.11.4 ImportError

I'm attempting to upgrade Django from 1.10.7 to 1.11.4 with Python 2.7.11. I've run pip install Django -U and python -c "import django; print django.get_version()" confirms that Django 1.11.4 is installed. However, when I then go to run tests, I get ImportError: No module named notmigrations. Does anyone have any advice?
Here is the full stack trace:
Traceback (most recent call last):
File "./manage.py", line 25, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/commands/test.py", line 29, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/commands/test.py", line 62, in handle
failures = test_runner.run_tests(test_labels)
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/test/runner.py", line 601, in run_tests
old_config = self.setup_databases()
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/test/runner.py", line 546, in setup_databases
self.parallel, **kwargs
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/test/utils.py", line 187, in setup_databases
serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 69, in create_test_db
run_syncdb=True,
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/__init__.py", line 130, in call_command
return command.execute(*args, **defaults)
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 83, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/migrations/loader.py", line 52, in __init__
self.build_graph()
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/migrations/loader.py", line 203, in build_graph
self.load_disk()
File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/migrations/loader.py", line 82, in load_disk
module = import_module(module_name)
File "/usr/local/lib/python2.7.11/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named notmigrations
It looks like you are using notmigrations in your MIGRATION_MODULES setting to disable migrations (as described in this post).
In Django 1.9+, you should simply use None instead of a fake module name like 'notmigrations' (release notes).
For Django 2.0 I create setting file as described here with content like:
from settings import *
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return None
MIGRATION_MODULES = DisableMigrations()
and run my tests with test newly created setting

Django Custom User migrate on heroku

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.

Django can't find specific test, but runs it if module is defined

I have some tests in myproject/core/tests/test_views_front.py. When I try to run python manage.py test myproject.core.tests.test_views_front I get:
NOTE: Using test database settings!
NOTE: Logging is disabled!
Traceback (most recent call last):
File "manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/__in
it__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/__in
it__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/comm
ands/test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/base
.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/comm
ands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/base
.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/south/management/commands/t
est.py", line 8, in handle
super(Command, self).handle(*args, **kwargs)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/comm
ands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/test/runner.py", lin
e 144, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/test/runner.py", lin
e 63, in build_suite
tests = self.test_loader.loadTestsFromName(label)
File "/usr/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'test_views_front'
This also happens if I run python manage.py test myproject.core.tests.test_views_front.FrontPageViewTests. However, if I simply run python manage.py test or python manage.py test myproject.core.tests then all the tests (including the ones in the aforementioned file) run fine. I found this solution but my test file seems to import fine, without any errors or warnings. Is there anything else I might be missing?
You can't run test from a specific file in Django. You can either run all the test from myproject.core.tests like you did or a specific TestCase:
myproject.core.tests.YourTestCase

Categories