python manage.py syncdb - python

I am very new to python and Django, was actually thrown in to finish off some coding for my company since our coder left for overseas.
When I run python manage.py syncdb I receive the following error
psycopg2.OperationalError: FATAL: password authentication failed for user "winepad"
I'm not sure why I am being prompted for user "winepad" as I've created no such user by that name, I am running the sync from a folder named winepad. In my pg_hba.conf file all I have is a postgres account which I altered with a new password.
Any help would be greatly appreciated as the instructions I left are causing me some issues.
Thank you in advance

Once you start a Django project, you have to set your database settings in your_project/settings.py . The settings you want to check/change is (assuming you use Django 1.3) something like this:
DATABASES = {
'default': {
'ENGINE': '',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
So make sure those settings are correctly set up (you have to do it manually)

Check your settings.py file. The most likely reason for this issue is that the username for the database is set to "winepad". Change that to the appropriate value and rerun python manage.py syncdb That should fix the issue.

Related

`manage.py inspectdb` tells me that I don't have an ENGINE specified in my default database, but the docs say that default can be blank

I'm creating a django web app that is going to be a database management portal for multiple databases. Because the web app will touch multiple databases, it doesn't make sense to have a default. However, when I run manage.py inspectdb I get an error saying that the ENGINE value isn't set on my database. It most definitely is.
Here's my DATABASES setting in settings.py
DATABASES = {
'default': {
},
'my_db': {
'NAME': 'my_db',
'USER': 'user',
'PASSWORD': 'pass',
'HOST': '192.168.0.255',
'PORT': '',
'ENGINE': 'sql_server.pyodbc',
'OPTIONS': {
'driver': 'ODBC Driver 13 for SQL Server',
},
},
}
If I run manage.py inspectdb using this setup I get this error:
settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
This doesn't make sense to me, since it says in the documentation that 'default' can be a blank {}.
However, if I supply a dummy NAME and ENGINE variable to the default db, it seems to work fine for the default DB, but it ignores my_db.
If I set default to look at my_db's information I get a login error (so I know at least something is working right there, even if my creds are bad).
So, what am I getting wrong in my database setup here?
You need to specify a database for which you need to inspectdb
python manage.py inspectdb --database your_db_name
For more details see the docs

Django: authentication for migrations across multiple machines?

I have been working on a Django app locally and it's now time to deploy it to a staging machine.
My Postgres database on the staging machine has a different username and password to my local machine.
I have got the Django app running okay on the remote machine, except that the database has not been initialised.
I assume that I should do this with migrate, so I try running:
$ python manage.py migrate
But I see the following error:
django.db.utils.OperationalError: FATAL: no pg_hba.conf entry
for host "127.0.0.1", user "mylocalusername", database "mylocaldbname"
It's failing because it doesn't allow me to log in with mylocalusername.
I assume that mylocalusername etc must be coming from the migrations files? Certainly the local username isn't set anywhere else on the staging machine, either in my settings file, or on the actual database itself.
How can I set up this database on the staging server?
I guess one way would be to delete everything in migrations and create a new local migration. Is that what I need to do?
I thought migrations were supposed to checked into source code, though, so I'd rather not delete all of them. Also, I want to carry on working on locally and updating my staging and production machines, so I need to find a sustainable way of doing this.
"mylocalusername" comes from settings.py file.
It should looks like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mylocaldbname', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'mylocalusername',
'PASSWORD': 'password',
'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
You can change it or create a valid user in your postgres database.

django-mongodb-engine and Django's native auth system

As stated in the title, I am using django-mongodb-engine and I am attempting to configure the native Django authentication framework. I've read some comments online that it should work out of the box sans some features. However, I couldn't find any tutorials and, furthermore, I am getting errors on trying to set it up on my own. The issue I'm having most certainly has to do with database permissions. I have included the Django middleware and apps per the Django docs. However, when I issue the syncdb command it fails with an error.
$ python manage.py syncdb
OperationFailure: database error: not authorized for query on MyDB.system.namespaces
settings.py
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'MyDB',
'USER': 'mySuperUser',
'PASSWORD': 'mypass',
'HOST': 'XXX.XXX.XXX.XXX',
'PORT': '',
},
# some other DBs
}
Mongo User Permissions
myDB> db.system.users.find()
{ "_id" : ObjectId("..."), "user" : "mySuperUser", "pwd" : "...", "roles" : [ "readWriteAnyDatabase", "userAdminAnyDatabase", "dbAdminAnyDatabase", "clusterAdmin" ] }
I'm not sure what other permissions I can grant this guy, and/or where else I need to create this user.
Any ideas?
After playing around, here is the solution. You must use the native mongo admin database. Thus, the required changes:
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'admin',
'USER': 'mySuperUser',
'PASSWORD': 'mypass',
'HOST': 'XXX.XXX.XXX.XXX',
'PORT': '',
},
# some other DBs
}
The user mySuperUser must naturally exist on the admin database. To be safe regarding authentication actions such as adding and removing users, I gave it the userAdminAnyDatabase privilege in mongo. The privileges are probably excessive, but I'd have to play with it to determine the proper scope of the required permissions. Here are the permissions:
// mongo
admin> db.system.users.find()
{ "_id" : ObjectId("..."), "pwd" : "...", "roles" : [ "readWriteAnyDatabase", "dbAdminAnyDatabase", "clusterAdmin", "userAdminAnyDatabase" ], "user" : "mySuperUser" }
Next, we can finally run the syncdb command:
$ python manage.py syncdb
Creating tables ...
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'someUser'):
Email address: someUser#user.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installing indices for admin.LogEntry model.
Installing indices for auth.Group_permissions model.
Installing indices for auth.Group model.
Installing indices for auth.User_groups model.
Installing indices for auth.User_user_permissions model.
Installing indices for auth.User model.
Installing indices for sessions.Session model.
Installed 0 object(s) from 0 fixture(s)
$
The problem for me was that I had not specified a SITE_ID in my settings.py. I did this:
./manage.py shell
>>>from django.contrib.sites.models import Site
>>>Site().save()
>>>Site.objects.all()[0].id
u'5391dbc22ebd1212246d50c4'
If you aren't 'django.contrib.sites' then I'm not sure why this would be a problem. Unless you had been using that module and already installed the collection/table to the database. In either case, this is how I got MongoDB to start working correctly again.
I encountered the same issue. My Mongo DB is hosted on MongoLab and I don't find any solutions to solve this error. Although that my user already exists in my DB, I don't want to use the admin database. Someone else has encountered the same problem or find a solution ?

how do I confirm django is working with xampp's mysql

I am starting to learn django , and I'm trying to set up a development environment as in http://www.venkysblog.com/setup-django-on-windows-with-apache-and-mysql. I'm having trouble getting it working and so I'm working backwards to make sure I have it all correct.
I'm ok up to step 4. I have confirmed python , xampp and django working . I have created a DB called django using phpmyadmin
I have a project called testproject, with the settings.py file including:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'post
'NAME': 'django', # Or path to database file if usi
'USER': 'root', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. No
'PORT': '', # Set to empty string for default. Not
}
}
when I run $ python manage.py runserver I get:
Validating models...
0 errors found
Django version 1.4.3, using settings 'testproject.settings'
Development server is running at htp://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Is there an explicit way to test the connection to 'django' db at this point?
Thanks in advance,
Bill
If you do manage.py syncdb it'll try to create your tables, and you'll know if it succeeded or failed.

How to fix "no fixtures found" when installing user management system in Django?

I'm trying to create a database in my first Django project (called "meu_blog"). I've create a file called gerar_banco_de_dados.bat and type the following code inside:
python manage.py syncdb
pause
The code in the settings file of project "meu_blog" is:
DATABASES = {
'default': {
'ENGINE': 'sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'meu_blog.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
But when I tryed to create a user management system with the following information:
•Username: admin
•E-mail: admin#gmail.com
•Password: 1
•Password (again): 1
I get a message saying: “no fixtures found”
When, instead, it should appear this message (according to the tutorial book I'm following):
So, I'd like to know how to fix this "no fixtures found" and get the user management system installed.
I'm using Python 2.6 and Django 1.3.
Thanks in advance for any help.
"No fixtures found" is not an error, per se. That will often show up during syncdb if you're not using initial_data.json fixtures for your apps (which is not required). There is no problem.
The user system is already installed, according to your screenshots.
The fixtures arent installed, mostly because you did not provide any.
See here https://docs.djangoproject.com/en/dev/howto/initial-data/#providing-initial-data-with-fixtures

Categories