简体   繁体   中英

Why does django/tastypie with postgresql concatenate models_?

I am using postgresql with django and tastypie. I have my models and resources set up and working with mongodb for certain models and am trying to use postgresql for relational data models. For some reason, when the query executes against postgresql, the folder (module) is concatenated to the table name and all the fields for said model:

"error_message": "relation \"models_member\" does not exist\nLINE 1: ..._member\".\"dob\", \"models_member\".\"last_login\" FROM \"models_me...\n                                                             ^\n",

Member Resource:

from api.models.member import Member
from django.conf.urls import url
from api.helper_methods import HelperMethods
from tastypie.resources import ModelResource
import json

class MemberResource(ModelResource):
    class Meta:
        max_limit = 0
        queryset = Member.objects.all().order_by('id')
        allowed_methods = ('get', 'post')
        resource_name = 'members'
        include_resource_uri = False

    def prepend_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/(?P<pk>[\w\d_.-]+)/$" % self._meta.resource_name, self.wrap_view('get_member'), name="api_get_member"),
        ]

    def get_member(self, request, **kwargs):
        member = Member.objects.get(id=kwargs['pk'])
        return self.create_response(request, member)

Member Model:

from tastypie.utils.timezone import now
from django.db import models

class Member(models.Model):
    id = models.IntegerField()
    fname = models.CharField()
    lname = models.CharField()
    addr1 = models.CharField()
    addr2 = models.CharField()
    city = models.CharField()
    state = models.CharField()
    zip = models.CharField()
    country = models.CharField()
    email = models.CharField()
    password = models.CharField()
    sex = models.CharField(max_length=6)
    dob = models.CharField()
    last_login = models.DateTimeField(default=now)

How do I tell my resource or... whatever... to say hey, don't concatenate anything, just make the call? I'm lost (and new to pythong/django/tastypie/all of the above).

Django prefixes table names with the name of the app in which they're defined and an underscore. Did you create the table in postgres manually or did you let django create it? You can tell django what the name of the table should be by setting db_table in the model's meta. More info in the docs .

class Member(models.Model):
    id = models.IntegerField()
    class Meta:
        db_table = 'member'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM