数据库错误没有这样的表django

时间:2013-07-15 10:15:20

标签: django django-models django-database

我在django项目'cc'中创建了一个新应用'api'。

我有一个远程数据库'launchg',我使用Legacies将它与Django集成,并使用python manage.py inspectdb > models.py生成models.py文件。

接下来将生成的models.py文件替换为api app中的models.py文件。

每当我尝试将查询发送到此数据库时database error:no such table 对于例如: - WebQuery.objects.all(),它会引发错误,说明database error: no such table : web_query

这是我的models.py文件

    # This is an auto-generated Django model module.
    # You'll have to do the following manually to clean this up:
    #     * Rearrange models' order  
    #     * Make sure each model has one field with primary_key=True
    # Feel free to rename the models, but don't rename db_table values or field names.
    #
    # Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'
    # into your database.
    from __future__ import unicode_literals

    from django.db import models  

    class Area(models.Model):
        area_id = models.BigIntegerField(primary_key=True)
        area_name = models.CharField(max_length=50L)
        class Meta:
            db_table = 'area'

    class Business2(models.Model):
        business_id = models.BigIntegerField(primary_key=True)
        b_name = models.CharField(max_length=50L)
        b_phone = models.CharField(max_length=50L)
        b_add = models.CharField(max_length=1000L)
        area_id = models.CharField(max_length=50L)
        categories = models.CharField(max_length=1000L)
        rating = models.IntegerField()
        latitude = models.CharField(max_length=255L)
        longitude = models.CharField(max_length=255L)
        class Meta:
            db_table = 'business2'

    class BusinessReply(models.Model):
        msg_id = models.BigIntegerField(primary_key=True)
        conversation_id = models.BigIntegerField()
        business_id = models.BigIntegerField()
        query_id = models.BigIntegerField()
        username = models.CharField(max_length=50L)
        message = models.CharField(max_length=500L)
        date_time = models.DateTimeField()
        class Meta:
            db_table = 'business_reply'

    class Businessnew(models.Model):
        business_id = models.BigIntegerField(primary_key=True)
        b_name = models.CharField(max_length=50L)
        b_phone = models.CharField(max_length=50L)
        b_add = models.CharField(max_length=1000L)
        area_id = models.CharField(max_length=50L)
        categories = models.CharField(max_length=1000L)
        rating = models.IntegerField()
        latitude = models.CharField(max_length=255L)
        longitude = models.CharField(max_length=255L)
        home_delivery = models.IntegerField(db_column='Home Delivery') # Field name made     lowercase. Field renamed to remove unsuitable characters.
        credit_card_facility = models.IntegerField(db_column='Credit Card facility') # Field name made lowercase. Field renamed to remove unsuitable characters.
        menu_available = models.IntegerField(db_column='Menu Available') # Field name made lowercase. Field renamed to remove unsuitable characters.
    bar_available = models.IntegerField(db_column='Bar Available') # Field name made lowercase. Field renamed to remove unsuitable characters.
        dine_in = models.IntegerField(db_column='Dine In') # Field name made lowercase. Field renamed to remove unsuitable characters.
        pure_vegetarian = models.IntegerField(db_column='Pure Vegetarian') # Field name made lowercase. Field renamed to remove unsuitable characters.
        cost = models.CharField(max_length=255L, db_column='Cost') # Field name made lowercase.
        timings = models.CharField(max_length=255L, db_column='Timings') # Field name made lowercase.
        check = models.IntegerField()
        url = models.CharField(max_length=500L)
        class Meta:
            db_table = 'businessnew'

     class BusinessnewBackup(models.Model):
         business_id = models.BigIntegerField(primary_key=True)
         b_name = models.CharField(max_length=50L)
    b_phone = models.CharField(max_length=50L)
    b_add = models.CharField(max_length=1000L)
    area_id = models.CharField(max_length=50L)
    categories = models.CharField(max_length=1000L)
    rating = models.IntegerField()
    latitude = models.CharField(max_length=255L)
    longitude = models.CharField(max_length=255L)
    home_delivery = models.IntegerField(db_column='Home Delivery') # Field name made lowercase. Field renamed to remove unsuitable characters.
    credit_card_facility = models.IntegerField(db_column='Credit Card facility') # Field name made lowercase. Field renamed to remove unsuitable characters.
    menu_available = models.IntegerField(db_column='Menu Available') # Field name made lowercase. Field renamed to remove unsuitable characters.
    bar_available = models.IntegerField(db_column='Bar Available') # Field name made lowercase. Field renamed to remove unsuitable characters.
    dine_in = models.IntegerField(db_column='Dine In') # Field name made lowercase. Field renamed to remove unsuitable characters.
    pure_vegetarian = models.IntegerField(db_column='Pure Vegetarian') # Field name made lowercase. Field renamed to remove unsuitable characters.
    cost = models.CharField(max_length=255L, db_column='Cost') # Field name made lowercase.
    timings = models.CharField(max_length=255L, db_column='Timings') # Field name made lowercase.
    check = models.IntegerField()
    class Meta:
        db_table = 'businessnew_backup'

class BusinessnewBackup1(models.Model):
    business_id = models.BigIntegerField(primary_key=True)
    b_name = models.CharField(max_length=50L)
    b_phone = models.CharField(max_length=50L)
    b_add = models.CharField(max_length=1000L)
    area_id = models.CharField(max_length=50L)
    categories = models.CharField(max_length=1000L)
    rating = models.IntegerField()
    latitude = models.CharField(max_length=255L)
    longitude = models.CharField(max_length=255L)
    home_delivery = models.IntegerField(db_column='Home Delivery') # Field name made lowercase. Field renamed to remove unsuitable characters.
    credit_card_facility = models.IntegerField(db_column='Credit Card facility') # Field name made lowercase. Field renamed to remove unsuitable characters.
    menu_available = models.IntegerField(db_column='Menu Available') # Field name made lowercase. Field renamed to remove unsuitable characters.
    bar_available = models.IntegerField(db_column='Bar Available') # Field name made lowercase. Field renamed to remove unsuitable characters.
    dine_in = models.IntegerField(db_column='Dine In') # Field name made lowercase. Field renamed to remove unsuitable characters.
    pure_vegetarian = models.IntegerField(db_column='Pure Vegetarian') # Field name made lowercase. Field renamed to remove unsuitable characters.
    cost = models.CharField(max_length=255L, db_column='Cost') # Field name made lowercase.
    timings = models.CharField(max_length=255L, db_column='Timings') # Field name made lowercase.
    check = models.IntegerField()
    class Meta:
        db_table = 'businessnew_backup1'

class BusinessnewBackup2(models.Model):
    business_id = models.BigIntegerField(primary_key=True)
    b_name = models.CharField(max_length=50L)
    b_phone = models.CharField(max_length=50L)
    b_add = models.CharField(max_length=1000L)
    area_id = models.CharField(max_length=50L)
    categories = models.CharField(max_length=1000L)
    rating = models.IntegerField()
    latitude = models.CharField(max_length=255L)
    longitude = models.CharField(max_length=255L)
    home_delivery = models.IntegerField(db_column='Home Delivery') # Field name made lowercase. Field renamed to remove unsuitable characters.
    credit_card_facility = models.IntegerField(db_column='Credit Card facility') # Field name made lowercase. Field renamed to remove unsuitable characters.
    menu_available = models.IntegerField(db_column='Menu Available') # Field name made lowercase. Field renamed to remove unsuitable characters.
    bar_available = models.IntegerField(db_column='Bar Available') # Field name made lowercase. Field renamed to remove unsuitable characters.
    dine_in = models.IntegerField(db_column='Dine In') # Field name made lowercase. Field renamed to remove unsuitable characters.
    pure_vegetarian = models.IntegerField(db_column='Pure Vegetarian') # Field name made lowercase. Field renamed to remove unsuitable characters.
    cost = models.CharField(max_length=255L, db_column='Cost') # Field name made lowercase.
    timings = models.CharField(max_length=255L, db_column='Timings') # Field name made lowercase.
    check = models.IntegerField()
    class Meta:
        db_table = 'businessnew_backup2'

class Businessowners(models.Model):
    b_phone = models.CharField(max_length=50L)
    b_id = models.IntegerField()
    userid = models.IntegerField(primary_key=True, db_column='UserID') # Field name made lowercase.
    firstname = models.CharField(max_length=100L)
    lastname = models.CharField(max_length=100L)
    email = models.CharField(max_length=150L)
    password = models.CharField(max_length=32L, db_column='Password') # Field name made lowercase.
    b_name = models.CharField(max_length=100L)
    b_address = models.CharField(max_length=255L)
    class Meta:
        db_table = 'businessowners'

class Categories(models.Model):
    cat = models.CharField(max_length=255L)
    syn = models.CharField(max_length=100L)
    class Meta:
        db_table = 'categories'

class CiSessions(models.Model):
    session_id = models.CharField(max_length=40L, primary_key=True)
    ip_address = models.CharField(max_length=45L)
    user_agent = models.CharField(max_length=120L)
    last_activity = models.IntegerField()
    user_data = models.TextField()
    class Meta:
        db_table = 'ci_sessions'

class Query(models.Model):
    query_id = models.BigIntegerField(primary_key=True)
    conversation_id = models.BigIntegerField()
    gcm_id = models.CharField(max_length=1000L)
    user_id = models.BigIntegerField()
    what = models.CharField(max_length=20L)
    where = models.CharField(max_length=500L)
    message = models.CharField(max_length=200L)
    date_time = models.DateTimeField()
    class Meta:
        db_table = 'query'

class QueryBusiness(models.Model):
    business_id = models.CharField(max_length=10L)
    query_id = models.BigIntegerField()
    date_time = models.DateTimeField()
    class Meta:
        db_table = 'query_business'

class TzMembers(models.Model):
    id = models.IntegerField(primary_key=True)
    usr = models.CharField(max_length=32L, unique=True)
    pass_field = models.CharField(max_length=32L, db_column='pass') # Field renamed because it was a Python reserved word.
    email = models.CharField(max_length=255L)
    regip = models.CharField(max_length=15L, db_column='regIP') # Field name made lowercase.
    dt = models.DateTimeField()
    class Meta:
        db_table = 'tz_members'

class Users(models.Model):
    user_id = models.BigIntegerField(primary_key=True)
    username = models.CharField(max_length=20L)
    fb_token = models.CharField(max_length=1000L)
    email = models.CharField(max_length=50L)
    facebook = models.CharField(max_length=50L)
    fb_likes = models.TextField()
    twitter = models.CharField(max_length=50L)
    gmail = models.CharField(max_length=50L)
    gcm_id = models.CharField(max_length=1000L)
    date_time = models.DateTimeField()
    last_login = models.DateTimeField()
    last_push = models.DateTimeField()
    class Meta:
        db_table = 'users'

class WebQuery(models.Model):
    query_id = models.BigIntegerField(unique=True)
    conversation_id = models.CharField(max_length=50L)
    u_id = models.CharField(max_length=50L)
    u_query = models.CharField(max_length=500L)
    sent_to = models.CharField(max_length=500L)
    date_time = models.DateTimeField()
    is_reply = models.IntegerField()
    is_responded = models.IntegerField()
    from_gingr = models.IntegerField()
    diff = models.IntegerField()
    class Meta:
        db_table = 'web_query'

class WebReply(models.Model):
    reply_id = models.IntegerField(primary_key=True)
    query_id = models.BigIntegerField()
    conversation_id = models.CharField(max_length=50L)
    b_id = models.CharField(max_length=20L)
    u_query = models.CharField(max_length=500L)
    user_id = models.CharField(max_length=20L)
    date_time = models.DateTimeField()
    diff = models.IntegerField()
    class Meta:
        db_table = 'web_reply'

class WebUsers(models.Model):
    user_id = models.BigIntegerField(primary_key=True)
    username = models.CharField(max_length=20L)
    fb_token = models.CharField(max_length=1000L)
    email = models.CharField(max_length=50L)
    facebook = models.CharField(max_length=50L)
    fb_likes = models.TextField()
    twitter = models.CharField(max_length=50L)
    gmail = models.CharField(max_length=50L)
    gcm_id = models.CharField(max_length=1000L)
    date_time = models.DateTimeField()
    last_login = models.DateTimeField()
    class Meta:
        db_table = 'web_users'

此外,当我输入命令manage.py sql api时,它会显示所有表格。这是什么???

请帮助!!!

1 个答案:

答案 0 :(得分:2)

主要区别在于,manage.py sql myapphere触发将显示用于为数据库创建模式的查询,而myapp.objects.all()的输出将仅返回该数据库中条目的列表。

例如,如果您有文章列表,则manage.py sql命令将显示myapp 属性,而myapp.objects.all()将显示myapp的实例< / em>在数据库中。

要进一步推断您的问题,请尝试打开您的数据库客户端,并确保列名称与模型中描述的列名称相匹配。如果它们不匹配,您可能需要删除表并重新同步数据库(我肯定有这个问题)。