在将sqLite迁移到Django的PostgreSQL的过程中出现以下错误。
psycopg2.DataError: value too long for type character varying(2)
我还提到了其他文章(1,2)。然后调查models.py文件,以查找是否设置了max_length=2
。但是,我什么也没有。
任何人都可以提出这个错误的原因是什么?
models.py
def dir_path(instance, filename):
return 'html/{0}/{1}'.format(instance.project, filename)
def idf_path(instance, filename):
return 'idf/{0}/{1}'.format(instance.project, filename)
def eso_path(instance, filename):
return 'eso/{0}/{1}'.format(instance.project, filename)
# Create your models here.
class html(models.Model):
project = models.CharField(max_length=50, blank=True)
version = models.IntegerField(blank=True,null=True)
ecms=models.ManyToManyField(ecm, blank=True)
diff = models.TextField(blank=True)
PROGRAM_CHOICES = (
('---', '---'),
('Office', 'General office'),
('Residential', 'Residential'),
('Retail', 'Retail'),
('Restaurant', 'Restaurant'),
('Grocery', 'Grocery store'),
('Medilcal', 'Hospital'),
('Research', 'R&D or laboratory'),
('Hotel', 'Hotel'),
('Daycare', 'Daycare'),
('K-12', 'Educational,K-12'),
('Postsecondary', 'Educational,postsecondary'),
('Airport', 'Airport'),
('DataCenter','Data Center'),
('DistributionCenter','Distribution center,warehouse')
)
program = models.CharField(max_length=20, choices=PROGRAM_CHOICES, default='---')
LOCATION_CHOICES = (
('---', '---'),
('Beijing', 'Beijing'),
('China', 'China'),
('Hong Kong', 'Hong Kong'),
('Japan', 'Japan'),
('Shanghai', 'Shanghai'),
('Shenzhen', 'Shenzhen'),
('Taiwan', 'Taiwan'),
('Thailand', 'Thailand'),
('USA', 'United States')
)
location = models.CharField(max_length=15, choices=LOCATION_CHOICES, default="---")
CERTIFICATE_CHOICES = (
('---', '---'),
('LEED_v3', 'LEED_v3'),
('LEED_v4', 'LEED_v4'),
('BEAM+', 'BEAM+'),
('WELL', 'WELL'),
('No certificate','No certificate')
)
certificate = models.CharField(max_length=20, choices=CERTIFICATE_CHOICES, default="---")
user = models.CharField(max_length=20, default='---')
html = models.FileField(upload_to=dir_path)
idf=models.FileField(upload_to=idf_path)
uploaded_at = models.DateTimeField(auto_now_add=True)
good = models.BooleanField(default=False)
final = models.BooleanField(default=False)
eso=models.FileField(upload_to=eso_path,blank=True)
compare = models.BooleanField(default=False)
def __str__(self):
return self.project+"_v"+str(self.version)
class timeseries(models.Model):
html = models.ForeignKey(html, on_delete=models.CASCADE)
keyword=models.CharField(max_length=50,default='test')
unit=models.CharField(max_length=20,default='test')
freq=models.CharField(max_length=20,default='test')
subcategories = models.TextField(default='test')
df=models.TextField(default='test')
@property
def category(self):
return self.keyword+" ["+self.unit+"]"
def __str__(self):
return str(self.html)+"_"+str(self.keyword)
class area(models.Model):
html = models.OneToOneField(html, primary_key=True, on_delete=models.CASCADE)
total_area = models.IntegerField()
condition_area = models.IntegerField()
uncondition_area = models.IntegerField()
class unmet(models.Model):
html = models.OneToOneField(html, primary_key=True, on_delete=models.CASCADE)
heating = models.FloatField()
cooling = models.FloatField()
ashrae = models.FloatField()
def total_unmet(self):
return self.heating+self.cooling
class wwr(models.Model):
html = models.OneToOneField(html, primary_key=True, on_delete=models.CASCADE)
total = models.FloatField()
north = models.FloatField()
east = models.FloatField()
south = models.FloatField()
west = models.FloatField()
class energy(models.Model):
html = models.OneToOneField(html, primary_key=True, on_delete=models.CASCADE)
total = models.FloatField()
euipertotal = models.FloatField()
euipercondition = models.FloatField()
class general(models.Model):
html = models.OneToOneField(html, primary_key=True, on_delete=models.CASCADE)
version=models.CharField(max_length=100,default='test')
weather=models.CharField(max_length=100,default='test')
lat=models.FloatField()
lon=models.FloatField()
elevation=models.FloatField()
northAngle=models.FloatField()
def ver_num(self):
return int(self.version.replace("EnergyPlus, Version ","")[2])
class summary(models.Model):
html = models.ForeignKey(html, on_delete=models.CASCADE,related_name='summaries')
keyword = models.CharField(max_length=50, default='test')
json = models.TextField(default='test')
def __str__(self):
return str(self.html)+" / "+str(self.keyword)
class loc(models.Model):
html = models.OneToOneField(html, primary_key=True, on_delete=models.CASCADE)
cooling=models.CharField(max_length=100, default='test')
eui=models.CharField(max_length=100, default='test')
euicon=models.CharField(max_length=100, default='test')
energy=models.CharField(max_length=100, default='test')
fan=models.CharField(max_length=100, default='test')
glass=models.CharField(max_length=100, default='test')
heatbal=models.CharField(max_length=100, default='test')
hvac=models.CharField(max_length=100, default='test')
hw=models.CharField(max_length=100, default='test')
light=models.CharField(max_length=100, default='test')
oa=models.CharField(max_length=100, default='test')
oamin=models.CharField(max_length=100, default='test')
opaque=models.CharField(max_length=100, default='test')
pump=models.CharField(max_length=100, default='test')
unmet=models.CharField(max_length=100, default='test')
wwr=models.CharField(max_length=100, default='test')
wwrcon=models.CharField(max_length=100, default='test')
zone = models.CharField(max_length=100, default='test')
#additional attribute (20/8/2017)
skywwr = models.CharField(max_length=100, default='test',blank=True)
coilC = models.CharField(max_length=100, default='test',blank=True)
coilH = models.CharField(max_length=100, default='test',blank=True)
daylight = models.CharField(max_length=100, default='test',blank=True)
exLight = models.CharField(max_length=100, default='test',blank=True)
heating = models.CharField(max_length=100, default='test',blank=True)
peak = models.CharField(max_length=100, default='test',blank=True)
peakSub = models.CharField(max_length=100, default='test',blank=True)
plant = models.CharField(max_length=100, default='test',blank=True)
#additional attribute(26/8/2017)
geometry = models.CharField(max_length=100, default='test',blank=True)
#additional attribute(15/10/2017)
sysventc = models.CharField(max_length=100, default='test',blank=True)
sysventh = models.CharField(max_length=100, default='test',blank=True)
zonevent = models.CharField(max_length=100, default='test',blank=True)
#additional attribute(20/01/2018)
zoneeui = models.CharField(max_length=100, default='test',blank=True)
# additional attribute(201/05/2018)
load = models.CharField(max_length=100, default='test', blank=True)
# additional attribute(7/6/2018)
tariff = models.CharField(max_length=100, default='test', blank=True)
prmc = models.CharField(max_length=100, default='test', blank=True)
eneCost = models.CharField(max_length=100, default='test', blank=True)
eflh = models.CharField(max_length=100, default='test', blank=True)
setp = models.CharField(max_length=100, default='test', blank=True)
def __str__(self):
return str(self.html)
答案 0 :(得分:1)
IMO,这是因为您在数据库中此字段的值超过2个字符。
您需要提供代码以及现在数据库中的内容。
此外,您可以将max_length
设置为2到更大的数字(例如255),以排除怀疑的可能性。