python manage.py migrate KeyError: 255 - python

Server environment configuration
Ubuntu 14
Django 1.11.3
Python 3.6.1
MySql 8.0.1
When I execute python manage.py dbshell command everything works ok.
But when I execute python manage.py migrate command, I get a KeyError: 255.
Here is the traceback:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 110, in handle
loader.check_consistent_history(connection)
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 282, in check_consistent_history
applied = recorder.applied_migrations()
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 254, in cursor
return self._cursor()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 229, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 274, in get_new_connection
conn = Database.connect(**conn_params)
File "/usr/local/lib/python3.6/site-packages/pymysql/__init__.py", line 90, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 706, in __init__
self.connect()
File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 931, in connect
self._get_server_information()
File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 1269, in _get_server_information
self.server_charset = charset_by_id(lang).name
File "/usr/local/lib/python3.6/site-packages/pymysql/charset.py", line 38, in by_id
return self._by_id[id]
KeyError: 255
moduleļ¼š
from django.db import models
class UserInfo (models.Model):
name = models.CharField(max_length=10)
tel = models.CharField(max_length=10)

use
manage.py makemigrations
then
manage.py migrate
You need to give the modal's code by the way.

Related

Django when running tests ValueError: Related model cannot be resolved. Related to previous migrations issue

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.

Q: Python Django Docker - Unknown server host 'db' error when trying to make a super user

I am trying to use the command python manage.py createsuperuser and docker exec -it veganetwork-db-1 python manage.py createsuperuser to add myself as a superuser to my microservices project, however when I try to run both of these commands I get Unknown server host 'db' in my Windows Powershell, here is the entire error:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.ProgrammingError: (1146, "Table 'veganetwork.auth_user' doesn't exist")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/manage.py", line 22, in <module>
main()
File "/app/manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
return super().execute(*args, **options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 100, in handle
default_username = get_default_username()
File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/management/__init__.py", line 140, in get_default_username
auth_app.User._default_manager.get(username=default_username)
File "/usr/local/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 425, in get
num = len(clone)
File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 269, in __len__
self._fetch_all()
File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 1308, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/usr/local/lib/python3.9/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'veganetwork.auth_user' doesn't exist")
PS C:\Users\trevo\OneDrive\Desktop\veganetwork\veganetworkmain> python manage.py migrate auth
Traceback (most recent call last):
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\mysql\base.py", line 234, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\__init__.py", line 123, in Connect
return Connection(*args, **kwargs)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\connections.py", line 185, in __init__
super().__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (2005, "Unknown server host 'db' (11001)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\trevo\OneDrive\Desktop\veganetwork\veganetworkmain\manage.py", line 22, in <module>
main()
File "C:\Users\trevo\OneDrive\Desktop\veganetwork\veganetworkmain\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\migrate.py", line 75, in handle
self.check(databases=[database])
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 419, in check
all_issues = checks.run_checks(
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\database.py", line 13, in check_database_backends
issues.extend(conn.validation.check(**kwargs))
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\mysql\validation.py", line 9, in check
issues.extend(self._check_sql_mode(**kwargs))
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\mysql\validation.py", line 13, in _check_sql_mode
if not (self.connection.sql_mode & {'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES'}):
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\mysql\base.py", line 405, in sql_mode
sql_mode = self.mysql_server_data['sql_mode']
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\mysql\base.py", line 366, in mysql_server_data
with self.temporary_connection() as cursor:
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 117, in __enter__
return next(self.gen)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 603, in temporary_connection
with self.cursor() as cursor:
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 259, in cursor
return self._cursor()
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 235, in _cursor
self.ensure_connection()
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\mysql\base.py", line 234, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\__init__.py", line 123, in Connect
return Connection(*args, **kwargs)
File "C:\Users\trevo\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\connections.py", line 185, in __init__
super().__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2005, "Unknown server host 'db' (11001)")
I have tried some other methods in some other posts like creating a class named Command in my manage.py script to create the superuser: Create django super user in a docker container without inputting password, using docker-compose run django python manage.py createsuperuser rather than the regular docker command which is docker exec -it veganetwork-db-1 python manage.py createsuperuser: https://github.com/vchaptsev/cookiecutter-django-vue/issues/25, and finally trying to change the depends_on variable inside my docker-compose.yml file and restarting the docker container itself: django.db.utils.OperationalError: (2005, "Unknown MySQL server host 'db' (-2)"). I have tried all of these solutions but they have all failed.
here is my docker-compose file as well as my dockerfile:
version: '3.9'
services:
backend:
build:
context: .
dockerfile: dockerfile
command: 'python manage.py runserver 0.0.0.0:8000'
ports:
- 8000:8000
volumes:
- .:/app
depends_on:
- db
db:
image: mysql:5.7.22
restart: always
environment:
MYSQL_DATABASE: veganetworkmain
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
volumes:
- .dbdata:/var/lib/mysql
ports:
- 3306:3306
dockerfile:
FROM python:3.9
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
COPY . /app
CMD python manage.py runserver 0.0.0.0:8000
What exactly am I doing wrong here, thank you!

Django Upgrade : relation "django_content type" does not exist

I upgraded my django version from 1.7.5 to 1.9.2. All migration ran but when i run tests i get below error.
django.db.utils.ProgrammingError: relation "django_content_type" does not exist
I checked the database and the django_content_type model exists. I am using PostgreSQL.
I am only getting this error on PostgreSQL not in Sqlite3..
Traceback
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 129, in
utility.execute()
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 104, in execute
PycharmTestCommand().run_from_argv(self.argv)
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 91, in handle
failures = TestRunner(test_labels, verbosity=verbosity, interactive=interactive, failfast=failfast, keepdb='--keepdb' in sys.argv)
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_runner.py", line 256, in run_tests
extra_tests=extra_tests, **options)
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_runner.py", line 156, in run_tests
return super(DjangoTeamcityTestRunner, self).run_tests(test_labels, extra_tests, **kwargs)
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/test/runner.py", line 532, in run_tests
old_config = self.setup_databases()
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/test/runner.py", line 482, in setup_databases
self.parallel, **kwargs
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/test/runner.py", line 726, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db
run_syncdb=True,
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/__init__.py", line 119, in call_command
return command.execute(*args, **defaults)
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 172, in handle
self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 293, in sync_apps
cursor.execute(statement)
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "django_content_type" does not exist
I used uuid field and JSON field in old Django version but in new version these fields are default provided by django models. So i replaced these fields with django default fields and created migrations again....
Now Its working without any issue..

Failing to open localhost page

I try to install django in my mac pro and I finished installing but when I want to run this command :
python manage.py runserver
Stack Feedback:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/core/management/commands/syncdb.py", line 25, in handle
call_command("migrate", **options)
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/core/management/commands/migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/migrations/loader.py", line 182, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/backends/base/base.py", line 162, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/backends/base/base.py", line 135, in _cursor
self.ensure_connection()
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/backends/base/base.py", line 119, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python2.7/site-packages/Django-1.8.4-py2.7.egg/django/db/backends/sqlite3/base.py", line 204, in get_new_connection
conn = Database.connect(**conn_params)
django.db.utils.OperationalError: unable to open database file
I then tried my sqlite3 in the python, it works.
So I wanna how can I do it?

Django manage.py syncdb Not Working

I am trying to learn django....
I am following a tutorial and got so far as making an app ....so i opened settings.py file, and i made these changes to 'NAME' AND 'ENGINE', according to the tutorial...here:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '~/django/bin/django_test/storage.db'
}
So later in the tutorial, it says that in order to actually make such a file "storage.db" to do this:
python manage.py syncdb
this was the result:
/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/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)
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/core/management/commands/syncdb.py", line 25, in handle
call_command("migrate", **options)
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/core/management/commands/migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/migrations/loader.py", line 180, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/backends/base/base.py", line 162, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/backends/base/base.py", line 135, in _cursor
self.ensure_connection()
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/backends/base/base.py", line 119, in connect
self.connection = self.get_new_connection(conn_params)
File "/Users/angel/django/lib/python2.7/site-packages/Django-1.8.1-py2.7.egg/django/db/backends/sqlite3/base.py", line 204, in get_new_connection
conn = Database.connect(**conn_params)
django.db.utils.OperationalError: unable to open database file>
The ~ sign is not expanded to you home dir so you have to manually pass the full absolute path to the database:
'NAME': '/home/yourname/django/bin/django_test/storage.db'
If django_test is the name of your django project then it is better to use the following code:
'NAME': os.path.join(BASE_DIR, 'storage.db'),

Categories