I have a very small (so far) legacy database which I auto-generate in Django using
python manage.py inspectdb > models.py
I put this in my python package that holds the app and added to my INSTALLED_APPS
setting.
I ran: python manage.py makemigrations app_name
Migrations for 'app_name': app_name/migrations/0002_auto_20180809_0453.py
Next: python manage.py migrate app_name
Operations to perform: Apply all migrations: app_name Running migrations: Applying app_name.0001_initial... OK Applying app_name.0002_auto_20180809_0453... OK
I checked that the models were created using: python manage.py sqlmigrate app_name 0001
, which showed that several models were created.
My models.py
file looks like this:
from __future__ import unicode_literals
from django.db import models
class Test(models.Model):
date = models.FloatField(blank=True, null=True)
shift = models.FloatField(blank=True, null=True)
timer = models.FloatField(blank=True, null=True)
target_produce = models.FloatField(blank=True,
null=True)
actual_produce = models.FloatField(blank=True,
null=True)
oee = models.FloatField(blank=True, null=True)
class Meta:
managed = False
db_table = 'Test'
I am trying to access my database from views.py
. Here is my code:
File: views.py
from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpResponse
from lineoee.models import Test
# Create your views here.
def index(request):
context = {}
lines = Test.objects.date() # <-- Error here
print(lines)
return render(request,
'lineoee/index.html',context)
I get the atribute error
'Manager' object has no attribute 'date'
I tried to implement the solution here and added the UserManager
import and objects = UserManager()
but I ended up with
'Usermanager' object has no attribute 'date'
Any suggestions on how I can eliminate this error and access data from my legacy database correctly?