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?
Related
I'm trying to deploy a Django application to Heroku, but the heroku returns the message when i run the migrate command on the heroku bash:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 82, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 61, in applied_migrations
if self.has_table():
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 44, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 255, in cursor
return self._cursor()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 232, in _cursor
self.ensure_connection()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not translate host name "postgres://baz" to address: Name or service not known
I think is something wrong with my settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': config('DB_NAME'),
'USER': config('DB_USER'),
'PASSWORD': config('DB_PASS'),
'HOST': 'localhost',
'PORT': config('DB_PORT'),
}
}
is that right? What do i must do to configure this?
I have a projects with hundreds of migrations. When I try to run the tests it gives me the stacktrace:
./manage.py test
Creating test database for alias 'default'...
Traceback (most recent call last):
File "/project/lib/python3.5/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
File "/project/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 326, in execute
return Database.Cursor.execute(self, query)
sqlite3.OperationalError: near "USING": syntax error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/project/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/project/lib/python3.5/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/project/lib/python3.5/site-packages/django/core/management/commands/test.py", line 29, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/project/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/project/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/project/lib/python3.5/site-packages/django/core/management/commands/test.py", line 62, in handle
failures = test_runner.run_tests(test_labels)
File "/project/lib/python3.5/site-packages/django/test/runner.py", line 601, in run_tests
old_config = self.setup_databases()
File "/project/lib/python3.5/site-packages/django/test/runner.py", line 546, in setup_databases
self.parallel, **kwargs
File "/project/lib/python3.5/site-packages/django/test/utils.py", line 187, in setup_databases
serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
File "/project/lib/python3.5/site-packages/django/db/backends/base/creation.py", line 69, in create_test_db
run_syncdb=True,
File "/project/lib/python3.5/site-packages/django/core/management/__init__.py", line 131, in call_command
return command.execute(*args, **defaults)
File "/project/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/project/lib/python3.5/site-packages/wagtail_modeltranslation/management/commands/migrate_translation.py", line 25, in handle
super(Command, self).handle(*args, **options)
File "/project/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/project/lib/python3.5/site-packages/django/db/migrations/executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/project/lib/python3.5/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/project/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/project/lib/python3.5/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/project/lib/python3.5/site-packages/django/db/migrations/operations/special.py", line 108, in database_forwards
self._run_sql(schema_editor, self.sql)
File "/project/lib/python3.5/site-packages/django/db/migrations/operations/special.py", line 133, in _run_sql
schema_editor.execute(statement, params=None)
File "/project/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 136, in execute
cursor.execute(sql, params)
File "/project/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/project/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/project/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/project/lib/python3.5/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
File "/project/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 326, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: near "USING": syntax error
From this alone I cannot seem to figure out the cause (which probably is a migration somewhere).
When I try to run the same command using a postgres database, I get a error
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/project/lib/python3.5/dist-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/project/lib/python3.5/dist-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/project/lib/python3.5/dist-packages/django/core/management/commands/test.py", line 29, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/project/lib/python3.5/dist-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/project/lib/python3.5/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/project/lib/python3.5/dist-packages/django/core/management/commands/test.py", line 62, in handle
failures = test_runner.run_tests(test_labels)
File "/project/lib/python3.5/dist-packages/django/test/runner.py", line 601, in run_tests
old_config = self.setup_databases()
File "/project/lib/python3.5/dist-packages/django/test/runner.py", line 546, in setup_databases
self.parallel, **kwargs
File "/project/lib/python3.5/dist-packages/django/test/utils.py", line 187, in setup_databases
serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
File "/project/lib/python3.5/dist-packages/django/db/backends/base/creation.py", line 69, in create_test_db
run_syncdb=True,
File "/project/lib/python3.5/dist-packages/django/core/management/__init__.py", line 131, in call_command
return command.execute(*args, **defaults)
File "/project/lib/python3.5/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/project/lib/python3.5/dist-packages/wagtail_modeltranslation/management/commands/migrate_translation.py", line 25, in handle
super(Command, self).handle(*args, **options)
File "/project/lib/python3.5/dist-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/project/lib/python3.5/dist-packages/django/db/migrations/executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/project/lib/python3.5/dist-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/project/lib/python3.5/dist-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/project/lib/python3.5/dist-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/project/lib/python3.5/dist-packages/django/db/migrations/operations/fields.py", line 221, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/project/lib/python3.5/dist-packages/django/db/backends/base/schema.py", line 531, in alter_field
old_db_params, new_db_params, strict)
File "/project/lib/python3.5/dist-packages/django/db/backends/postgresql/schema.py", line 112, in _alter_field
new_db_params, strict,
File "/project/lib/python3.5/dist-packages/django/db/backends/base/schema.py", line 635, in _alter_field
new_default = self.effective_default(new_field)
File "/project/lib/python3.5/dist-packages/django/db/backends/base/schema.py", line 245, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "/project/lib/python3.5/dist-packages/django/db/models/fields/__init__.py", line 770, in get_db_prep_save
prepared=False)
File "/project/lib/python3.5/dist-packages/django/db/models/fields/__init__.py", line 762, in get_db_prep_value
value = self.get_prep_value(value)
File "/project/lib/python3.5/dist-packages/django/db/models/fields/__init__.py", line 1043, in get_prep_value
return self.to_python(value)
File "/project/lib/python3.5/dist-packages/django/db/models/fields/__init__.py", line 1036, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'N' value must be either True or False."]
Since I use the value N all over the project, this does not help much either.
How do I go about finding the migration that causes these errors?
You can add the --verbosity of -v option when running your tests, which adds more verbosity to the output of your tests:
python manage.py test -v 2
or
python manage.py test --verbosity=2
Level 2 should show you all the migrations. Level 3 even shows more details, but I don't think it'll add much in your case.
This will show you which migration is causing the issue.
I tried changing my db from sqlite3 to postgresql using this tutorial:
https://tutorial-extensions.djangogirls.org/en/optional_postgresql_installation/
but when i try to migrate i get the following error
Traceback (most recent call last):
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\backends\base\base.py", line 213, in ensure_connection
self.connect()
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\backends\base\base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\backends\postgresql\base.py", line 176, in get_new_connection
connection = Database.connect(**conn_params)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
psycopg2\__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\core\management\__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\core\management\commands\migrate.py", line 83, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\migrations\executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\migrations\loader.py", line 52, in __init__
self.build_graph()
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\migrations\loader.py", line 209, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\migrations\recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\migrations\recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_name
s(self.connection.cursor()):
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\backends\base\base.py", line 254, in cursor
return self._cursor()
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\backends\base\base.py", line 229, in _cursor
self.ensure_connection()
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\backends\base\base.py", line 213, in ensure_connection
self.connect()
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\backends\base\base.py", line 213, in ensure_connection
self.connect()
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\backends\base\base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
django\db\backends\postgresql\base.py", line 176, in get_new_connection
connection = Database.connect(**conn_params)
File "c:\Users\gudat\Documents\Arbeit\Szenario\Python\venv1\lib\site-packages\
psycopg2\__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError
in my settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'dbase',
'USER': 'name',
'PASSWORD': 'test',
'HOST': 'localhost',
'PORT': '5432',
}
}
(yes i had the name changed)
Using Python 3.6.3 and psycopg2 (2.7.4).
What am i doing wrong?
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.
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'),