划过的梦神 2018-09-14 07:34 采纳率: 33.3%
浏览 359

django 1.6 采用mysql数据库,表同步失败。

我的modles代码如下:

 #coding:utf-8
'''
Created on 2013-11-11
@author: Administrator
'''
from __future__ import unicode_literals
from django.db import models
import time

class FaqCategory(models.Model):
    id = models.AutoField(primary_key=True)
    catname = models.CharField(max_length=150L, blank=True)
    class Meta:
        db_table = 't_faq_category'
        verbose_name = u'faq_category'
        verbose_name_plural = u'faq_category'
        app_label = u'My_Category'
    def __unicode__(self):
        return self.catname

class ProductCategory(models.Model):
    id = models.AutoField(primary_key=True)
    catname = models.CharField(max_length=150L, blank=True)
    class Meta:
        db_table = 't_product_category'
        verbose_name = u'product_category'
        verbose_name_plural = u'product_category'
        app_label = u'My_Category'
    def __unicode__(self):
        return self.catname

class ServiceCategory(models.Model):
    id = models.AutoField(primary_key=True)
    catname = models.CharField(max_length=150L, blank=True)
    class Meta:
        db_table = 't_service_category'
        verbose_name = u'service_category'
        verbose_name_plural = u'service_category'
        app_label = u'My_Category'
    def __unicode__(self):
        return self.catname

class AboutCategory(models.Model):
    id = models.AutoField(primary_key=True)
    catname = models.CharField(max_length=150L, blank=True)
    class Meta:
        db_table = 't_about_category'
        verbose_name = u'about_category'
        verbose_name_plural = u'about_category'
        app_label = u'My_Category'
    def __unicode__(self):
        return self.catname

class DownloadCategory(models.Model):
    id = models.AutoField(primary_key=True)
    catname = models.CharField(max_length=150L, blank=True)
    class Meta:
        db_table = 't_download_category'
        verbose_name = u'download_category'
        verbose_name_plural = u'download_category'
        app_label = u'My_Category'
    def __unicode__(self):
        return self.catname

class Announcement(models.Model):
    id = models.IntegerField(primary_key=True)
    title = models.CharField(max_length=100L , blank = False , verbose_name = "Title")
    content = models.TextField( blank = False , verbose_name = "Content")
    createddate = models.DateField(null=True, db_column='createdDate', blank=True , default=time.strftime('%Y-%m-%d'),verbose_name='Date')
    class Meta:
        db_table = u't_announcement'
        verbose_name = u'announcement'
        verbose_name_plural = u'announcement'
        app_label = u'My_Company'

class Products(models.Model):
    id = models.IntegerField(primary_key=True)
    catid = models.ForeignKey(ProductCategory,db_column= 'catid',to_field='id',blank=False,verbose_name = 'catid') 
    product_name = models.CharField(max_length=200L , verbose_name = "Name")
    product_simple_desc = models.TextField(blank=True , verbose_name = "Simple Desc")
    product_full_desc = models.TextField(blank=True , verbose_name = "Full Desc")
    product_pic = models.CharField(max_length=200L, blank=True , verbose_name = "Picture Path")
    product_order = models.IntegerField(verbose_name = "Order")
    createddate = models.DateField(db_column='createdDate', blank=True , default=time.strftime('%Y-%m-%d') , verbose_name = "Created Date") # Field name made lowercase. This field type is a guess.
    class Meta:
        db_table = 't_products'
        verbose_name = u'products'
        verbose_name_plural = u'products'
        app_label = u'My_Company'

class News(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=255L, blank=True ,verbose_name = "Title")
    content = models.TextField(blank=True , verbose_name = "Content")
    createddate = models.DateField(null=True, db_column='createdDate', blank=True , default=time.strftime('%Y-%m-%d') , verbose_name = "Created Date") # Field name made lowercase.
    class Meta:
        db_table = 't_news'
        verbose_name = u'news'
        verbose_name_plural = u'news'
        app_label = u'My_Company'

class Download(models.Model):
    id = models.AutoField(primary_key=True)
    catid = models.ForeignKey(DownloadCategory,db_column= 'catid',to_field='id',blank=False,verbose_name = 'catid') 
    title = models.CharField(max_length=150L, blank=True)
    content = models.TextField(blank=True)
    downloadurl = models.CharField(max_length=200L, blank=True)
    createddate = models.DateField(null=True, db_column='createdDate', blank=True) # Field name made lowercase.
    class Meta:
        db_table = 't_download'
        verbose_name = u'download'
        verbose_name_plural = u'download'
        app_label=u"My_Company"

class Faq(models.Model):
    id = models.AutoField(primary_key=True)
    catid = models.ForeignKey(FaqCategory,db_column= 'catid',to_field='id',blank=False,verbose_name = 'catid')    
    title = models.CharField(max_length=150L, blank=True ,verbose_name = 'title')
    content = models.TextField(blank=True,verbose_name = 'content')
    class Meta:
        db_table = 't_faq'
        verbose_name = u'faq'
        verbose_name_plural = u'faq'
        app_label=u"My_Company"

class Service(models.Model):
    id = models.AutoField(primary_key=True)
    catid = models.ForeignKey(ServiceCategory,db_column= 'catid',to_field='id',blank=False,verbose_name = 'catid') 
    title = models.CharField(max_length=150L, blank=True)
    content = models.TextField(blank=True)
    class Meta:
        db_table = 't_service'
        verbose_name = u'service'
        verbose_name_plural = u'service'
        app_label=u"My_Company"

class About(models.Model):
    id = models.AutoField(primary_key=True)
    catid = models.ForeignKey(AboutCategory,db_column= 'catid',to_field='id',blank=False,verbose_name = 'catid')
    title = models.CharField(max_length=150L, blank=True)
    content = models.TextField(blank=True)
    class Meta:
        db_table = 't_about'
        verbose_name = u'about'
        verbose_name_plural = u'about'
        app_label=u"My_Company"

图片说明
图片说明
mysql没有那几个表,一直报错。
syncdb命令也没有用。

  • 写回答

1条回答

  • lshen01 2023-03-16 09:47
    关注

    参考GPT和自己的思路:

    根据你提供的信息和截图,可以看出你想要创建一个名为"My_Company"和"My_Category"的应用程序,并且它们使用的数据表分别为"t_announcement"、"t_products"、"t_news"、"t_download"、"t_faq"、"t_service"和"t_about"。但是出现了表同步失败的问题,同步命令也无法解决。

    首先需要确认的是,你在settings.py文件中已经正确配置了数据库信息,如下所示:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'database_name',
            'USER': 'username',
            'PASSWORD': 'password',
            'HOST': '127.0.0.1',
            'PORT': '3306',
        }
    }
    

    另外,要使用"python manage.py syncdb"同步数据库前,请确认以下步骤:

    1. 创建一个名为"My_Company"和"My_Category"的应用程序

    2. 在相应的models.py文件中创建Model

    3. 运行以下命令:

        python manage.py makemigrations
        python manage.py migrate
      

      如果还是无法同步成功,建议检查数据库连接,如数据库名称、用户名、密码、主机以及端口等配置是否正确,确保与MySQL实际运行的环境一致,这些信息可以在MySQL图形化客户端中查看或者从MySQL的配置文件中查看。若还不行,可能会需要重建数据库或重新安装MySQL。

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?