django.db.utils.DataError:值对于类型字符变化(30)太长,我在heroku postgresql上迁移时遇到此错误

eufgjt7s  于 2023-01-31  发布在  Go
关注(0)|答案(3)|浏览(184)

在PostgreSQL Heroku上迁移时遇到的错误。注意:它在本地服务器上工作正常。

Traceback (most recent call last):
      File "/app/manage.py", line 22, in <module>
        main()
      File "/app/manage.py", line 18, in main
        execute_from_command_line(sys.argv)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
        utility.execute()
      File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
        self.execute(*args, **cmd_options)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
        output = self.handle(*args, **options)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 89, in wrapped
        res = handle_func(*args, **kwargs)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 244, in handle
        post_migrate_state = executor.migrate(
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/executor.py", line 117, in migrate
        state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
        state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
        state = migration.apply(state, schema_editor)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/migration.py", line 126, in apply
        operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/operations/fields.py", line 104, in database_forwards
        schema_editor.add_field(
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 522, in add_field
        self.execute(sql, params)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 145, in execute
        cursor.execute(sql, params)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
        return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
        return executor(sql, params, many, context)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
        return self.cursor.execute(sql, params)
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
        raise dj_exc_value.with_traceback(traceback) from exc_value
      File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
        return self.cursor.execute(sql, params)
    **django.db.utils.DataError: value too long for type character varying(30)**

没有长度为30的列,即使在删除所有数据后尝试迁移,仍然得到相同的错误。
这是www.example.com项目的模型models.py

from django.db import models
    from django.contrib.auth.models import User
    from django.db.models.fields import AutoField
    from django.utils.timezone import now
    
    class pageinfo(models.Model):
        page_id=models.IntegerField(AutoField,primary_key=True);
        # thumbnail=models.ImageField(null=True,blank=True);
        channellink=models.URLField(null=True,default='#')
        logo= models.URLField(null=True,blank=True);
        youtube_link1=models.URLField(null=True,default='#')
        youtube_link2=models.URLField(null=True,default='#')
        title=models.CharField(max_length=150,null=True);
        display_title=models.CharField(max_length=150,null=True);
        subscriber=models.CharField(max_length=15,null=True);
        description=models.TextField(null=True)
        ratingtitle1=models.CharField(max_length=150,default='Course Depth')
        ratingtitle2=models.CharField(max_length=150,default='Language Clarity')
        ratingtitle3=models.CharField(max_length=150,default='How interactive videos are')
        ratingtitle4=models.CharField(max_length=150,default='Quality of Content')
    
    # Create your models here.
    class review(models.Model):
        # id=models.ForeignKey(pageinfo,on_delete=models.CASCADE,primary_key=True)
        comment=models.CharField(max_length=1000,null=True);
        type=models.CharField(max_length=120,null=False)
        username= models.ForeignKey(User,on_delete=models.CASCADE, null=True);
        timeStamp=models.DateTimeField(default=now)
        
    class rating(models.Model):
        # id=models.ForeignKey(pageinfo,on_delete=models.CASCADE,primary_key=True)
        rate=models.IntegerField();
        type=models.CharField(max_length=120,null=False)
        username= models.ForeignKey(User,on_delete=models.CASCADE,null=True);
        email=models.CharField(max_length=80,default='')
        timeStamp=models.DateTimeField(default=now)
    
    class languagerating(models.Model):
        # id=models.ForeignKey(pageinfo,on_delete=models.CASCADE,primary_key=True)
        rate=models.IntegerField();
        type=models.CharField(max_length=120,null=False)
        email=models.CharField(max_length=80,default='')
        username= models.ForeignKey(User,on_delete=models.CASCADE,null=True);
        timeStamp=models.DateTimeField(default=now)
    
    class interactionrating(models.Model):
        # id=models.ForeignKey(pageinfo,on_delete=models.CASCADE,primary_key=True)
        rate=models.IntegerField();
        type=models.CharField(max_length=120,null=False)
        email=models.CharField(max_length=80,default='')
        username= models.ForeignKey(User,on_delete=models.CASCADE,null=True);
        timeStamp=models.DateTimeField(default=now)
    
    
    
    class qualityrating(models.Model):
        # id=models.ForeignKey(pageinfo,on_delete=models.CASCADE,primary_key=True)
        rate=models.IntegerField();
        type=models.CharField(max_length=120,null=False)
        email=models.CharField(max_length=80,default='')
        username= models.ForeignKey(User,on_delete=models.CASCADE,null=True);
        timeStamp=models.DateTimeField(default=now)
    
    # class user_detai(models.Model):
    #   username=models.CharField(max_length=50);
    #   email=models.CharField(max_length=50)
    #   password=models.CharField( max_length=50)
        
    class Info(models.Model):
      name=models.CharField(max_length=40,default='')
      email=models.CharField(max_length=80, null=True, );
      comment=models.CharField(max_length=1000, null=True);
lnlaulya

lnlaulya2#

在您的pageinfo模型中,看起来

subscriber=models.CharField(max_length=15,null=True);

尝试增加此字段的max_length,然后重新运行makemigrations和migrate命令。

xqnpmsa8

xqnpmsa83#

该错误是由于数据库中已保存的数据的长度超过了给定的字符数。您可能需要查看该数据并考虑修复它,或者考虑给定的字符数是否确实是您想要的限制。
如果要维护模型的历史,则还需要删除历史表中的数据。

相关问题