I'm getting a connection refused error while trying to run my tests
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
The but problem is that my DB settings are not pointing to loop address. My DB is actually running on a separated container (docker-composer) so i reach him with project_api_db_1
address. Which works fine while testing the server manually with run server
the problem is at the unit tests. I've never seen this before :/ why Django is ignoring my host address?
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "api_db",
"USER": "postgres",
"PASSWORD": "postgres",
"HOST": "project_api_db_1",
"PORT": "5432",
"TEST": {
"HOST": "project_api_db_1"
}
},
overlay
network
project_api_db
, not the instance of container name.
Save
button for all of them. Is this possible?
someone can help me.
i use multiple site, multiple env, multiple project, multiple database.
and found this error message if use DATABASE_ROUTER
.
insert or update on table "django_admin_log" violates foreign key constraint "django_admin_log_user_id_c564eba6_fk_auth_user_id"
DETAIL: Key (user_id)=(1) is not present in table "auth_user".
i already tried with this answer: http://stackoverflow.com/a/20094869/6396981 or https://code.djangoproject.com/ticket/23297, but still an error.
if i do migration with following DATABASE_ROUTER
, i found an error django.db.utils.ProgrammingError: relation "auth_user" does not exist
. this why we migrated first my second database and then setup the DATABASE_ROUTER
after doing migration.
settings.py : http://pastebin.com/zWjy0z3R
myproject/routers.py: http://pastebin.com/M9i4KVew
thnk so much before..
i implemented the model to save the id from user from another db with integer field and not FK.
models.py : http://pastebin.com/EXtcM85b
if we try to check my Users, it work well. but not for default:
>>> from django.contrib.auth.models import User
>>> User.objects.all()
[<User: user_a>, <User: user_b>, <User: user_c> ]
>>>
>>> User.objects.using('default')
[]
>>> User.objects.using('auth_db')
[<User: user_a>, <User: user_b>, <User: user_c> ]
>>>
typo:DATABASE_ROUTER
meanDATABASE_ROUTERS
'''
def decode_base64(data):
missing_padding = len(data) % 4
if missing_padding != 0:
data += b'='* (4 - missing_padding)
return data.decode('base64')
def pdf_view(request):
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="densitycurve.pdf"'
(graph,outputText) = processData(misc.densitycurve)
outputList = string.split(outputText, "\n")
p = canvas.Canvas(response)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
for i in range(len(outputList)):
outputList[i] = string.lstrip(outputList[i])
p.drawString(100, 10*i+100, outputList[i])
#p.drawString(100, 60, "Report created with FSC iCalc")
image = open("image.png", "wb")
image = ImageReader(decode_base64(graph))
p.drawImage(image, 100, 350)
image.close()
p.showPage()
p.save()
return response
'''
I have question regarding the User model in Django. My Django app is open for public registration, via email/password, Facebook, Twitter,…
Django will serve mobile devices and web, so I would be using JWT and web session/cookie for authentication.
My question is, should I use the default model from Django auth contrib and extends it a little bit, or should I create a totally separated model?
views.py
def bemember(request):
if request.method == 'POST':
form = becomemember(request.POST)
if form.is_valid():
beamember_obj = form.save(commit=True)
surname = form.cleaned_data['surname']
firstname = form.cleaned_data['firstname'],
othername = form.cleaned_data['othername'],
email = form.cleaned_data['email'],
phone = form.cleaned_data['phone'],
password = form.cleaned_data['password'],
confirmpassowrd = form.cleaned_data['confirmpassword'],
marital = form.cleaned_data['marital'],
gender = form.cleaned_data['gender'],
work = form.cleaned_data['work'],
address = form.cleaned_data['address'],
workdetails = form.cleaned_data['workdetails'],
identity = form.cleaned_data['identity'],
idno = form.cleaned_data['idno']
return HttpResponseRedirect('/beamember/')
else:
form = becomemember()
return render(request, 'beamember/beamember.html', {'form': form})