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'),
Related
I am trying to do python manage.py migrate to do migrations for my django app but i keep getting this error even though i have supplied the db name, user, password in settings.py.
Any help will be appreciated.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'accountant',
'USER': 'json',
'PASSWORD': '******',
'HOST': 'localhost',
'PORT': '5432'
}
}
Full stacktrace:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/core/management/__init__.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/core/management/base.py", line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/core/management/base.py", line 445, in execute
output = self.handle(*args, **options)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/migrations/loader.py", line 191, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/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 "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/base/base.py", line 162, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/base/base.py", line 135, in _cursor
self.ensure_connection()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/utils.py", line 98, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/base/base.py", line 119, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/json/anaconda3/envs/py33/lib/python3.8/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: fe_sendauth: no password supplied
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 am new to django, I was running the command
python manage.py migrate
and got this error.
(py1) G:\django\djangoproject1>python manage.py migrate Traceback
(most recent call last): File "manage.py", line 22, in
execute_from_command_line(sys.argv) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management__init__.py",
line 364, in execute_from_command_line
utility.execute() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management__init__.py",
line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management\base.py",
line 283, in run_from_argv
self.execute(*args, **cmd_options) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management\base.py",
line 327, in execute
self.check() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management\base.py",
line 359, in check
include_deployment_checks=include_deployment_checks, File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\management\commands\migrate.py",
line 61, in _run_checks
issues = run_checks(tags=[Tags.database]) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\checks\registry.py",
line 81, in run_checks
new_errors = check(app_configs=app_configs) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\core\checks\database.py",
line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs)) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\mysql\validation.py",
line 9, in check
issues.extend(self._check_sql_mode(**kwargs)) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\mysql\validation.py",
line 13, in _check_sql_mode
with self.connection.cursor() as cursor: File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\base\base.py",
line 254, in cursor
return self._cursor() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\base\base.py",
line 229, in _cursor
self.ensure_connection() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\base\base.py",
line 213, in ensure_connection
self.connect() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\utils.py", line
94, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\base\base.py",
line 213, in ensure_connection
self.connect() File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\base\base.py",
line 189, in connect
self.connection = self.get_new_connection(conn_params) File "C:\Users\Mahin\Envs\py1\lib\site-packages\django\db\backends\mysql\base.py",
line 274, in get_new_connection
conn = Database.connect(**conn_params) File "C:\Users\Mahin\Envs\py1\lib\site-packages\MySQLdb__init__.py", line
84, in Connect
return Connection(*args, **kwargs) File "C:\Users\Mahin\Envs\py1\lib\site-packages\MySQLdb\connections.py",
line 164, in init
super(Connection, self).init(*args, **kwargs2) django.db.utils.OperationalError: (1045, "Access denied for user
'root'#'localhost' (using password: YES)")
Since I should have magically known your settings.py DB config and my post was deleted for not answering the question without "requiring clarification from the asker" I'm reposting to try and help. The default password for root user in a mysql db is "", that is its left blank. Right now there is a mismatch between your db and the configuration you provided in your settings.py file. Go into your dbms and make sure that the setting for the database match the ones you provided in your settings.py.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB NAME',
'USER': 'USER NAME',
'PASSWORD':'USER PW',
'HOST' : 'localhost',
}
}
If these match to your db you should be able to now migrate.
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 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?