Django: How to access test database? - python

I am working in Django 1.8. I have a Django management command to create materialized views on my database, as follows:
python manage.py create_db_matviews $DB_NAME $DB_USER $DB_PASS
Now I want to run the management command from inside my tests, so that I can test the command. (My actual database is extremely large, and the management command is extremely slow, so I would like to test it on test data, rather than real data.)
However calling the management command from inside my test file does not work - unsurprisingly since I have no idea what credentials to use:
def setUpModule():
management.call_command('loaddata', 'frontend/fixtures/mydata.json',
verbosity=0)
# load fixtures, then...
management.call_command('create_db_matviews',
'default', 'default', 'randomguess',
verbosity=0)
It fails as follows:
Creating test database for alias 'default' ('test_prescribing')...
... running migrations...
======================================================================
ERROR: setUpModule (frontend.tests.test_api_views)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/.../tests/test_api_views.py", line 23, in setUpModule
verbosity=0)
File "/Users/.../.virtualenvs/openprescribing/lib/python2.7/site-packages/django/core/management/__init__.py", line 115, in call_command
return klass.execute(*args, **defaults)
File "/Users/.../.virtualenvs/openprescribing/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/.../frontend/management/commands/create_indexes_and_matviews.py", line 19, in handle
password=db_pass)
File "/Users/.../.virtualenvs/openprescribing/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
OperationalError: FATAL: role "default" does not exist
What credentials should I use to get access to the test database?

This section of the Django docs has the details.
Basically the name of the test database is as per your settings file but with test_ prefixed, and the user and password are as your settings file.

Related

ValueError: The field admin.LogEntry.user was declared with a lazy reference

I'm developing a new django project and stuck with migration.
I would like to make a UserModel, and in order to do that, I did two things so far.
1. I made AuthUser model and set a Meta class in the class below.
In models.py
class AuthUser(AbstractUser):
user_type_id = models.PositiveIntegerField(choices=UserTypes.choices())
user_id = models.PositiveIntegerField()
class Meta(AbstractUser.Meta):
swappable = 'AUTH_USER_MODEL'
#property
def user_type(self):
return UserTypes(self.user_type_id)
def original_orm(self):
if self.user_type.value == UserTypes.raijosha.value:
return RaijoshaUsers.objects.filter(id=self.user_id).first()
elif self.user_type.value == UserTypes.shuttennsha.value:
return Users.objects.filter(id=self.user_id).first()
In settings.py, I set AUTH_USER_MODEL.
AUTH_USER_MODEL = 'recommend.AuthUser'
Here's the error codes.
Operations to perform:
Apply all migrations: admin, auth, contenttypes, recommend, recommend_raijousha, sessions
Traceback (most recent call last):
File "manage.py", line 25, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-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/dist-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/commands/migrate.py", line 164, in handle
pre_migrate_apps = pre_migrate_state.apps
File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/state.py", line 218, in apps
return StateApps(self.real_apps, self.models)
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/state.py", line 295, in __init__
raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'recommend.authuser', but app 'recommend' doesn't provide model 'authuser'.
Could you please help us or give me an advise.
Applying admin.0001_initial...Traceback (most recent call last):
File "manage.py", line 25, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-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/dist-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/usr/local/lib/python3.6/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 "/usr/local/lib/python3.6/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 "/usr/local/lib/python3.6/dist-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/operations/models.py", line 97, in database_forwards
schema_editor.create_model(model)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/schema.py", line 254, in create_model
definition, extra_params = self.column_sql(model, field)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/schema.py", line 144, in column_sql
db_params = field.db_parameters(connection=self.connection)
File "/usr/local/lib/python3.6/dist-packages/django/db/models/fields/related.py", line 994, in db_parameters
return {"type": self.db_type(connection), "check": self.db_check(connection)}
File "/usr/local/lib/python3.6/dist-packages/django/db/models/fields/related.py", line 991, in db_type
return self.target_field.rel_db_type(connection=connection)
File "/usr/local/lib/python3.6/dist-packages/django/db/models/fields/related.py", line 909, in target_field
return self.foreign_related_fields[0]
File "/usr/local/lib/python3.6/dist-packages/django/db/models/fields/related.py", line 653, in foreign_related_fields
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
File "/usr/local/lib/python3.6/dist-packages/django/db/models/fields/related.py", line 640, in related_fields
self._related_fields = self.resolve_related_fields()
File "/usr/local/lib/python3.6/dist-packages/django/db/models/fields/related.py", line 625, in resolve_related_fields
raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'recommend.authuser' cannot be resolved
Considering an advise, I did delete migration files.
But another error occured shown above.
It happens if you ran default auth app migrations and later changed the AUTH_USER_MODEL in settings.py. You can try following:
# comment AUTH_USER_MODEL in settings.py so it points to default User model
python manage.py migrate auth zero
# uncomment to be AUTH_USER_MODEL='recommend.AuthUser'
python manage.py migrate auth
I delete all the migration files and database and applied it.
Then I could migrate.
Note : I am using sqlite3 as a database.
Hi,
I easily solved it by deleting all the migration files in the migrations folder except the __init__.py file. And also delete db.sqlite3. Now run the following commands : python manage.py makemigrations and then python manage.py migrate. Now you'll have to create the super user once again, so for this just type the following commmand : python manage.py createsuperuser. Then it will prompt for username, email and password, so enter your credentials and all will continue to work properly once again I hope that this will be helpful.
Click Here To View Image
For me helped split on two migration
create new table (with out connection betwin new and old tables and without AUTH_USER_MODEL = 'recommend.authuser')
add AUTH_USER_MODEL to settins.py and other connections with new table
I had to refer to this stack: to be able to solve that issue.
I simply followed the steps bellow:
Since I am not using sqlite, I made new database configuration that refers to my postgres, in my settings.py:
old database i am not more going to use:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'leszexpert', 'USER': 'postgres', 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '5432', } }
new database I want to start using:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'leszexpert_db', 'USER': 'postgres', 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '5432', } }
As you can see, the difference is the DATABASE NAME (referenced after ENGINE)!!!!!!
I stopped the server and already previously deleted all existing corresponding migrations.
I closed my IDE VScode (I have realised from experience that when something does not take effect, after closing it and reopening it, it most time ends up taking effect)
when I reopened the code editor, I uncomment my models (i commented them previously), then VERY VERY IMPORTANT: DO NOT START OR RUN YOUR SERVER AT THIS POINT. because now you are about to operate on the new database specified above and the issue as you know we are trying to solve is that if you run migration of that type of models after runing the server, it will not create your model...therefore DO NOT RUN SERVER YET
INSTEAD DO THIS: RUN MIGRATIONS AND THEN MIGRATE
ET VOILA (French expression to That is it): your extended user model will be created in your database:
Thank you for reading my answer
I'm using MySQL.
The solution, for me, was to delete the files inside migrations folder (all but __ init__.py), DROP and CREATE database in MySQL Workbench and run python manage.py makemigrations and python manage.py migrate again.
Therefore, I had to create a new superuser and all my data was lost :(
If you are still in development and can take the pain of filling out the db data again then here's what all you need to know!.
you need to first delete all the files related with db(including sqlite.py if it exists), you can do this by the help of below following ways.
find . -path "/migrations/.py" -not -name "init.py" -delete
find . -path "/migrations/.pyc" -delete
Now either delete the entire data,tables of your DB or just Drop the db and make a new one and do the migrations separately for each app and migrate it.
python manage.py makemigrations appname
python manage.py migrate appname
then if you get any error for the session like "ProgrammingError: relation "django_session" does not exist"
then follow these steps below:
python manage.py migrate --fake sessions zero
then your sessions migrate will be
python manage.py showmigrations
sessions
[ ] 0001_initial
then migrate with --fake-initial again
python manage.py migrate --fake-initial
now do try to the runserver again and the problem must have been by gone now, if not then please let me know,I'll try my best possible way to solve it.
Thanks for looking at this.
If your migration works locally and not on server do this for server;
root#abcomp:~/var/www/yourapp$sudo -u postgres psql
#list your databases
postgres=#\l
postgres=#\c your_dbname;
your_db=# delete from django_migrations;
# after pulling the latest working changes
(venv)root#abcomp/var/www/yourapp$./manage.py migrate --fake

Django: "Cannot add foreign key constraint" when creating test tables before running unit tests

I am trying to run unit tests that I've written for my Django project, but testing fails at the database creation stage. I have a single database "test", one of which as a foreign key relationship with another. I run the following:
python3 manage.py test --settings myapp.settings_test
And see the following output:
Creating test database for alias 'test'...
Got an error creating the test database: (1007, "Can't create database 'test_test'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_test', or 'no' to cancel: yes
Destroying old test database for alias 'test'...
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 374, in _do_query
db.query(q)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/connections.py", line 277, in query
_mysql.connection.query(self, query)
_mysql_exceptions.IntegrityError: (1215, 'Cannot add foreign key constraint')
I've seen many answers such as this: Django MySQL error when creating tables.
Such answers show that, in general, this error is caused by adding a table that has a foreign key field before adding the table that the foreign key referencing. However, I have not found many helpful answers on how to address this in a testing scenario.
Other things I have tried:
I've tried to run tests in a Django shell so that I can then use "django.db.connection" to show the raw MySQL commands Django is running, but I can't seem to figure out how to run the tests in the Django shell.
I've tried to run tests without migrations (https://pypi.org/project/django-test-without-migrations/) but that seems to have no effect.
In my test settings file, I added the MIGRATION_MODULES variable to address the app "badapp" that has the foreign key field:
MIGRATION_MODULES = {
'badapp': None
}
but this made no difference as well.
I would like to know:
1.) How can I verify that this error is caused by adding tables in the incorrect order?
2.) How can I force tables to be added in a specific order when running tests?
Based on your reddit version of the question, you have 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" set in the database options. What happens when you remove that? And what's your default storage engine (I'm assuming InnoDB but want to check)?
This error can occur if you specify a custom MIGRATION_MODULES entry that points to a path that does not contain a __init__.py.
In my case was a problem with the migrations, i run
python manage.py test --verbosity=3
to check the execution trace, after verifying the trace I could see that the tables of my models were not being created, so i execute
python manage.py makemigrations
and the test can run perfectly It should be noted that my models do not have foreign keys, so the error was quite strange.

No schema has been selected to create in ... error

I am working on a Linux server that is hosted on Amazon's server and I have completely set up the server. The final thing I am trying to do is host one of my old projects that I created on the server which is in the Flask framework.
I am trying to run the Python file that sets up my database that is required to run my project.
I am using a virtual machine inside the server that will run my project and every time I run the command I get the following error:
(venv) grader#ip-10-20-6-95:/var/www/catalog/catalog$ python setup_database.py
Traceback (most recent call last):
File "setup_database.py", line 63, in <module>
Base.metadata.create_all(engine)
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/schema.py", line 2848, in create_all
tables=tables)
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1479, in _run_visitor
conn._run_visitor(visitorcallable, element, **kwargs)
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1122, in _run_visitor
**kwargs).traverse_single(element)
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 122, in traverse_single
return meth(obj, **kw)
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/ddl.py", line 70, in visit_metadata
self.traverse_single(table, create_ok=True)
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 122, in traverse_single
return meth(obj, **kw)
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/ddl.py", line 89, in visit_table
self.connection.execute(schema.CreateTable(table))
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 662, in execute
params)
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 720, in _execute_ddl
compiled
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 874, in _execute_context
context)
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1024, in _handle_dbapi_exception
exc_info
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 196, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb)
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 867, in _execute_context
context)
File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 324, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) no schema has been selected to create in
'\nCREATE TABLE users (\n\tid SERIAL NOT NULL, \n\tusername VARCHAR(100), \n\temail VARCHAR(225) NOT NULL, \n\tprofile_pic VARCHAR(225) NOT NULL, \n\tPRIMARY KEY (id)\n)\n\n' {}
I am not sure why I get this error.
The commands I ran to set up PostgreSQL (if that should matter):
$ sudo apt-get install libpq-dev python-dev
$ sudo apt-get install postgresql postgresql-contrib
$ sudo su - postgres
$ psql
# CREATE USER catalog WITH PASSWORD 'sillypassword';
# ALTER USER catalog CREATEDB;
# CREATE DATABASE catalog WITH OWNER catalog;
# \c catalog
# REVOKE ALL ON SCHEMA public FROM public;
# GRANT ALL ON SCHEMA public TO catalog;
# \q
$ exit
How could I fix this problem?
no schema has been selected to create in
You get this error when your search_path setting has no valid first entry (typically empty). Postgres does not know in which schema to create the table.
Fix your search_path setting, or schema-qualify object names (like: public.users). But fix your search_path in any case.
Details:
How does the search_path influence identifier resolution and the "current schema"
This issue was answered already: https://dba.stackexchange.com/a/275116/114247
The fix is:
grant usage on schema public to public;
grant create on schema public to public;
I found the file created by pg_dump (under postgres 10.7) had
SELECT pg_catalog.set_config('search_path', '', false);
near the top of it. So when importing the file, it manipulated the search path, which persisted throughout the current session.
Commenting that line out (and starting a new session) fixed the problem.
You do not have a schema created. Create a schema using CREATE SCHEMA public;
then you can execute grant usage on schema public to public; and grant create on schema public to public
I was stuck across same problem and after doing a lot of research, I got the below solution, assuming you are using flask models to create database using sqlalchemy:
while creating models use the below command before defining columns of models:
__table_args__ = {"schema":"schema_name"}
Hope this helps you out.

issues with OpenERP installation

I am installing openerp at my local server, I have installed it and its dependences but after finishing its installation when i run server 'openerp-server' and acces it using 0.0.0.0:8069/. I got the following error
OpenERP Server Error
Client Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/http.py", line 195, in dispatch
response["result"] = method(self, **self.params)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/controllers/main.py", line 709, in get_list
return db_list(req)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/controllers/main.py", line 88, in db_list
dbs = proxy.list()
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/session.py", line 31, in proxy_method
result = self.session.send(self.service_name, method, *args)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/session.py", line 104, in send
raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)
Server Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/addons/web/session.py", line 90, in send
return openerp.netsvc.dispatch_rpc(service_name, method, args)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/netsvc.py", line 295, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/service/web_services.py", line 122, in dispatch
return fn(*params)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/service/web_services.py", line 351, in exp_list
cr = db.cursor()
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/sql_db.py", line 477, in cursor
return Cursor(self._pool, self.dbname, serialized=serialized)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/sql_db.py", line 183, in __init__
self._cnx = pool.borrow(dsn(dbname))
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/sql_db.py", line 378, in _locked
return fun(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130211_002141-py2.7.egg/openerp/sql_db.py", line 433, in borrow
result = psycopg2.connect(dsn=dsn, connection_factory=PsycoConnection)
File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect
connection_factory=connection_factory, async=async)
OperationalError: FATAL: role "ghrix" does not exist
I haven't recognize this error.
One more thing , I haven't edit OpenERP server configuration file . And if I have to edit this file then what are those changes.
Thanks.
This error indicates that OpenERP is trying to connect to the PostgreSQL database server using the "ghrix" user, which does not exist. This is probably the user under which you are starting the server.
If you have created a special database user for OpenERP you need to specify it on the command-line using --db_user=DB_USER (and in that case you probably also need --db_host=localhost and --db-password=YOUR_PASSWORD).
If you haven't created any database user yet, the easiest solution is probably to create one named ghrix, e.g.:
$ sudo su - postgres
$ createuser -s ghrix # -s to make a super-user that can create DBs
Note: Use ./openerp-server --help to see all possible startup parameters for the OpenERP server. You can also put the command-line options in a config file: just execute
$ ./openerp-server -s
and then edit the sample config file that is created in $HOME/.openerp_serverrc
Even though the question has been answered, the following is a concise tutorial on installing a production grade OpenERP Server, that also explains how to set up the database, manage access rights and configure your OpenERP installation:
http://www.theopensourcerer.com/2012/02/how-to-install-openerp-6-1-on-ubuntu-10-04-lts/
you should check two case
First case:
$ sudo su - postgres $ createuser -s ghrix
second case
fill the db user and db password in
/odoo/debian/odoo.conf
run odoo with this parameter
./odoo-bin -c /opt/odoo/debian/odoo.conf
If not resolved comment below i try to resolve it

MySQL 1045 exception

I use Django 1.3.1 & Python 2.7.2 and I'm trying to deploy a project locally with nginx.
Something wrong with manage.py after executing the first command. For example: the first command is:
$ python manage.py runfcgi host=127.0.0.1 port=7782
and it works correctly. But when I try to execute any command after that, like syncdb or anything else (runserver, validate, runfcgi, etc...), I get strange exceptions:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 102, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 338, in get_server_version
self.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 250, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 322, in _cursor
self.connection = Database.connect(**kwargs)
File "/usr/lib/pymodules/python2.7/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: NO)")
I don't know what the reason is. In settings.py all MySQL access parameters (user, pass, dbname & host) are written correctly (syncdb succeed).
Note: if I copy the project directory for example to "project2" and rename it to original "project", the problem disappears for the first manage.py command I exectue, after that, I see the exceptions again.
I have another django projects deployed in the same way, using same django & python, but they work without any problem.
Anybody knows what the problem is?
Is your other Django project is set up on the same server/computer?
If it is, check your commas when you giving your db credentials and compare with the one which is running.

Categories

Resources