zoukankan      html  css  js  c++  java
  • 日常记Bug

    前记:后端写代码应该对数据的交互更加掌握,不要被编码、数据模型细节坑住


    Unicode编码、Django数据迁移偶尔产生的不稳定

    处理细项工资记录模型:

    class TeachRoll(models.Model):  # 教学细项工资管理(教学加班,德育补助,安全补助等等)
        staff = models.ForeignKey(basic_models.Staff)
        item = models.ForeignKey(basic_models.TeachItem)  # 注意这个是teachitem
        teach_time = models.FloatField(default='0')  # 教学课时支持浮点数
        the_price = models.FloatField(default='0')  # 当时这条课时记录的课时单价
        money = models.FloatField()  # 教学细项工资记录的价格
        give_time = models.CharField(max_length=64)  # '年月'
        create_time = models.DateTimeField(auto_now_add=True)
        update_time = models.DateTimeField(auto_now_add=True)
    
        class Meta:
            # unique_together = ('staff', 'teach_time', 'give_time')  # 同员工同条目同年月工资记录不可重复
            unique_together = ('staff', 'item', 'give_time')  # 同员工同条目同年月工资记录不可重复
    

    模型建立时因为没注意,把unique的三个属性写错了,从而视图函数根据staff,item,give_time检查没有记录,导致视图函数中create记录时报错,还以为是编码问题,找了许久。'7-0-2019'???。对数据库迁移和数据交互还是要更加细心和深入理解。

  • 相关阅读:
    Javascript 生成全局唯一标识符 (GUID,UUID)
    nginx 与location语法详解
    nginx的安装与使用
    Linux上python3的安装和使用
    Linux上Redis安装和简单操作
    MySQL + centos +主从复制
    web服务基础
    linux系统基础优化及高级操作命令
    vim编辑
    Linux的基本命令
  • 原文地址:https://www.cnblogs.com/bqwzx/p/10735000.html
Copyright © 2011-2022 走看看