Python: ValueError: недопустимый литерал для int () с основанием 10: '', но не может найти ошибку - PullRequest
0 голосов
/ 30 октября 2018

Я не уверен, где проблема с моим приложением. Я не внес никаких изменений, но теперь у меня есть эта действительная ошибка int. Вот ошибка:

ProgrammingError at /restaurant/orders/
column yummyApp_order.delivered_at does not exist
LINE 1: ...der"."created_at", "yummyApp_order"."picked_at", "yummyApp...
                                                             ^
Request Method:	GET
Request URL:	https://yummy-.herokuapp.com/yummy/orders/
Django Version:	1.10
Exception Type:	ProgrammingError
Exception Value:	
column yummyApp_order.delivered_at does not exist
LINE 1: ...der"."created_at", "yummyApp_order"."picked_at", "yummyApp...

Когда я пытаюсь выполнить миграцию, я получаю эту ошибку: ValueError: недопустимый литерал для int () с основанием 10: ''

Но у моих "заказов" есть в поставке в моделях:

delivered_at = models.DateTimeField(default = timezone.now)

Я не вижу проблемы. Помогите!

Обновление 1:

Вот мои модели:

class Order(models.Model):
    PICKING = 1
    READY = 2
    ONTHEWAY = 3
    DELIVERED = 4

    CANCELED = 5


    STATUS_CHOICES = (
    (PICKING, "Your Order Is Being Picked!"),
    (READY, "Picked, Weighed, And Ready For Delivery."),
    (ONTHEWAY, "We Are Heading Straight To Your Door."),
    (DELIVERED, "Delivered"),

    (CANCELED, "Canceled/Refunded")
    )

    customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
    dispensary = models.ForeignKey(Dispensary, on_delete=models.CASCADE)
    driver = models.ForeignKey(Driver, blank = True, null = True, on_delete=models.CASCADE)
    address = models.CharField(max_length=500)
    total = models.FloatField()
    status = models.IntegerField(choices = STATUS_CHOICES)
    created_at = models.DateTimeField(default = timezone.now)
    picked_at = models.DateTimeField(default = timezone.now)
    delivered_at = models.DateTimeField(default = timezone.now)

Вот мой след:

Environment:


Request Method: GET
Request URL: https://yummy-.herokuapp.com/restaurant/orders/

Django Version: 1.10
Python Version: 3.6.3
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'yummysapp',
 'oauth2_provider',
 'social_django',
 'rest_framework_social_oauth2',
 'bootstrap3',
 'multiselectfield',
 'openinghours',
 'rest_framework',
 'whitenoise.runserver_nostatic',
 'django_s3_storage']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware']


Template error:
In template /app/yummysapp/templates/restaurant/orders.html, error at line 28
   column yummysapp_order.delivered_at does not exist
LINE 1: ...der"."created_at", "yummysapp_order"."picked_at", "yummysapp...
                                                             ^
   18 :             <th>Customer</th>
   19 :             <th>Total</th>
   20 :             <th>Status</th>
   21 :             <th>Action</th>
   22 :             <th>Driver Name</th>
   23 :             <th>Cancel Order</th>
   24 : 
   25 :           </tr>
   26 :         </thead>
   27 :         <tbody>
   28 :            {% for order in orders %} 
   29 : 
   30 :             <tr>
   31 :               <td scope="row">{{ order.id }}</td>
   32 :               <td>
   33 :                 {% for od in order.order_details.all %}
   34 : 
   35 :                {{ od.product_size.product.name }}: {{ od.product_size.get_size_display }} ( {{ od.product_size.price|floatformat:2 }}
   36 :                   x {{ od.quantity }} ) = ${{ od.sub_total|floatformat:2 }}.
   37 :                 {% endfor %}
   38 :               </td>


Traceback:

File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

The above exception (column yummysapp_order.delivered_at does not exist
LINE 1: ...der"."created_at", "yummysapp_order"."picked_at", "yummysapp...
                                                             ^
) was the direct cause of the following exception:

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  39.             response = get_response(request)

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/app/yummysapp/views.py" in restaurant_orders
  172.     return render(request, 'restaurant/orders.html', {"orders": orders})

File "/app/.heroku/python/lib/python3.6/site-packages/django/shortcuts.py" in render
  30.     content = loader.render_to_string(template_name, context, request, using=using)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader.py" in render_to_string
  68.     return template.render(context, request)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py" in render
  66.             return self.template.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
  208.                     return self._render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
  199.         return self.nodelist.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  174.         return compiled_parent._render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
  199.         return self.nodelist.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  174.         return compiled_parent._render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
  199.         return self.nodelist.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  70.                 result = block.nodelist.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/defaulttags.py" in render
  166.             len_values = len(values)

File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in __len__
  238.         self._fetch_all()

File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in _fetch_all
  1085.             self._result_cache = list(self.iterator())

File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in __iter__
  54.         results = compiler.execute_sql()

File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
  835.             cursor.execute(sql, params)

File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)

File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py" in __exit__
  94.                 six.reraise(dj_exc_type, dj_exc_value, traceback)

File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/six.py" in reraise
  685.             raise value.with_traceback(tb)

File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /restaurant/orders/
Exception Value: column yummysapp_order.delivered_at does not exist
LINE 1: ...der"."created_at", "yummysapp_order"."picked_at", "yummysapp...

Но, только когда драйвер завершит заказ, мы должны иметь order.delivered_at. Это указано здесь:

@csrf_exempt
def driver_complete_order(request):
    # Get token

    driver = JWTAuthentication().authenticate(request)[0].driver
    # driver = access_token.user.driver

    order = Order.objects.get(id = request.POST.get('order_id'), driver = driver)
    order.status = Order.DELIVERED
    order.delivered_at = timezone.now()
    order.save()

    update = CustomerDetailSerializer()

    return JsonResponse({"status": "success"})
...