django.db.utils.ProgrammingError: relation "bot_trade" does not exist

Dominic M.

I am attempting to set up a website on cookeicutter, I created a new app called "bots" and added a class called Trade within models that lists 2 parameters, "titles" and "units". After migrating and running the server, when I open the admin panel and click on the "+ add" button within the panel to create a trade (see picture). The Django Webpage returns this error:

django.db.utils.ProgrammingError: relation "bot_trade" does not exist
LINE 1: ...."id", "bots_unit"."sell", "bots_unit"."buy" FROM "bots_unit...

Additonal Info: Running my django within a docker with postgreSQL

pic of admin panel

Models.py

from django.db import models
from datetime import date
#from django.contrib.auth.models import AbstractUser
#from .models import User
from django.urls import reverse
from django.urls import reverse_lazy
from django.conf import settings
import uuid


class Unit(models.Model):

TRADE_UNIT = (
    ('ETH', 'Ethereum'),
    ('BTC', 'Bitcoin'),
    ('LTC', 'Litecoin'),
    ('IOT', 'IOTA'),
    ('OMG', 'OmiseGo'),
    ('BCH', 'BitcoinCash'),

)

sell = models.CharField(max_length=3, choices=TRADE_UNIT, blank=True, default='ETH', help_text='Currency to Sell')
buy = models.CharField(max_length=3, choices=TRADE_UNIT, blank=True, default='BTC', help_text='Currency to Buy')

def get_absolute_url(self):
    """
    Returns the url to access a particular author instance.
    """
    return reverse('unit-detail', args=[str(self.id)])

def __str__(self):
    """
    String for representing the Model object.
    """
    return '%s, %s' % (self.sell, self.buy)

class Meta:
    db_table = 'bots_unit'
    ordering = ['sell','buy']


class Trade(models.Model):
title = models.CharField(max_length=200)
unit = models.ForeignKey('Unit', on_delete=models.SET_NULL, null=True)


def __str__(self):
    """
    String for representing the Model object.
    """
    return self.title

def get_absolute_url(self):
    """
    Returns the url to access a particular book instance.
    """
    return reverse('trade-detail', args=[str(self.id)])

class Meta:
    db_table = 'bots_trade'


class TradeInstance(models.Model):
"""
Model representing a specific copy of a book (i.e. that can be borrowed from the library).
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text="Unique ID for this particular trade across whole database")
trade = models.ForeignKey('Trade', on_delete=models.SET_NULL, null=True)
amount = models.CharField(max_length=200)
price = models.CharField(max_length=200)
imprint = models.CharField(max_length=200)
time_initiated = models.DateTimeField(null=True, blank=True)
#initiator = models.ForeignKey(AbstractUser, 
on_delete=models.SET_NULL, null=True, blank=True)

position_status = (
    ('L', 'Long'),
    ('S', 'Short'),
)

position = models.CharField(max_length=1, choices=position_status, blank=True, default='L', help_text='Order Type')

class Meta:
    ordering = ["position"]


def __str__(self):
    """
    String for representing the Model object
    """
    return '%s (%s)' % (self.id,self.trade.title)

Admin.py

from django.contrib import admin
from .models import Trade, TradeInstance, Unit



# Define the admin class
@admin.register(Trade)
class TradeAdmin(admin.ModelAdmin):
    pass


@admin.register(Unit)
class UnitAdmin(admin.ModelAdmin):
    pass

UPDATE1: I deleted the content inside the migrations folder a few times, but this is what is currently inside of '0001.initial.py' after running 'makemigrations' and 'migrate':

# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2017-10-12 17:55
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Trade',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=200)),
            ],
        ),
        migrations.CreateModel(
            name='TradeInstance',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, help_text='Unique ID for this particular trade across whole database', primary_key=True, serialize=False)),
                ('amount', models.CharField(max_length=200)),
                ('price', models.CharField(max_length=200)),
                ('imprint', models.CharField(max_length=200)),
                ('time_initiated', models.DateTimeField(blank=True, null=True)),
                ('position', models.CharField(blank=True, choices=[('L', 'Long'), ('S', 'Short')], default='L', help_text='Order Type', max_length=1)),
                ('trade', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='bots.Trade')),
            ],
            options={
                'ordering': ['position'],
            },
        ),
        migrations.CreateModel(
            name='Unit',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('sell', models.CharField(blank=True, choices=[('ETH', 'Ethereum'), ('BTC', 'Bitcoin'), ('LTC', 'Litecoin'), ('IOT', 'IOTA'), ('OMG', 'OmiseGo'), ('BCH', 'BitcoinCash')], default='ETH', help_text='Currency to Sell', max_length=3)),
                ('buy', models.CharField(blank=True, choices=[('ETH', 'Ethereum'), ('BTC', 'Bitcoin'), ('LTC', 'Litecoin'), ('IOT', 'IOTA'), ('OMG', 'OmiseGo'), ('BCH', 'BitcoinCash')], default='BTC', help_text='Currency to Buy', max_length=3)),
            ],
            options={
                'ordering': ['sell', 'buy'],
            },
        ),
        migrations.AddField(
            model_name='trade',
            name='unit',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='bots.Unit'),
        ),
    ]

When I run 'showmigrations':

dominic@dom-Inspiron-7559:~/Desktop/Projects/vickibot/vicki$ docker-compose -focal.yml run django python manage.py showmigrations
Postgres is up - continuing...
account
 [X] 0001_initial
 [X] 0002_email_max_length
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
bots
 [X] 0001_initial
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
sessions
 [X] 0001_initial
sites
 [X] 0001_initial
 [X] 0002_alter_domain_unique
 [X] 0003_set_site_domain_and_name
socialaccount
 [X] 0001_initial
 [X] 0002_token_max_lengths
 [X] 0003_extra_data_default_dict
users
 [X] 0001_initial

UPDATE2:

'manage.py migrate --fake bots zero' output:

dominic@dom-Inspiron-7559:~/Desktop/Projects/vickibot/vicki$ **docker-compose -f local.yml run django python manage.py migrate --fake bots zero**
Postgres is up - continuing...
Operations to perform:
  Unapply all migrations: bots
Running migrations:
  Rendering model states... DONE
  Unapplying bots.0001_initial... FAKED

'manage.py migrate bots' output:

dominic@dom-Inspiron-7559:~/Desktop/Projects/vickibot/vicki$ docker-compose -f local.yml run django python manage.py migrate bots
Postgres is up - continuing...
Operations to perform:
  Apply all migrations: bots
Running migrations:
  Applying bots.0001_initial... OK
Alasdair

You probably haven't created any migrations for your bot app. You need to specify the app name to create the initial migrations:

./manage.py makemigrations bot

Then run migrate to run the migration and create the missing table:

./manage migrate

When you run showmigrations, you can see that Django thinks that it has already applied the initial migration for your bots app. This could be because you ran --fake for that app.

bots
 [X] 0001_initial

You can tell Django to mark the migrations as unapplied, then rerun the migration with:

manage.py migrate --fake bots zero
manage.py migrate bots

This should work, as long as no tables from the bots app have been created yet. If only some of the tables have been created, then fixing up the database will be much trickier.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

django.db.utils.ProgrammingError: relation "..." does not exist

django.db.utils.ProgrammingError: relation does not exist with recursive model

Django test fails with 'django.db.utils.ProgrammingError: relation "django_content_type" does not exist'

django.db.utils.ProgrammingError: relation "django_content_type" does not exist

Django Rest Framework "django.db.utils.ProgrammingError: relation "patient" does not exist"

"django.db.utils.ProgrammingError: relation "auth_user" does not exist" Django V2.0

django.db.utils.ProgrammingError: Could not load : column "" of relation "" does not exist

One more "django.db.utils.ProgrammingError: relation "device_gclouddevice" does not exist"

django.db.utils.ProgrammingError: relation "company_company" does not exist when running makemigrations

django.db.utils.ProgrammingError: type "raster" does not exist

ProgrammingError: relation "django_session" does not exist

ProgrammingError: relation "django_site" does not exist

django.db.utils.ProgrammingError: relation already exists on OenBSD vps

django.db.utils.ProgrammingError: column am.amcanorder does not exist

django.db.utils.ProgrammingError: type "int4range" does not exist

django.db.utils.ProgrammingError: column calculator_calculation._id does not exist using heroku and djongo

django.db.utils.ProgrammingError: Table doesn't exist

Python Django - Internal Error ProgrammingError relation does not exist

Getting error while syncdb django.db.utils.ProgrammingError: permission denied for relation django_migrations

Steps to Troubleshoot "django.db.utils.ProgrammingError: permission denied for relation django_migrations"

django.db.utils.ProgrammingError: column "image" of relation "choices_keyword" already exists

"django.db.utils.ProgrammingError: relation already exists" for unique together constraint

django.db.utils.ProgrammingError: (1146, "Table 'med_portal.Custparent' doesn't exist")

ProgrammingError at / relation "main_post" does not exist

django.db.utils.OperationalError: FATAL: role "django" does not exist

Django - ProgrammingError - column does not exist

django.db.utils.ProgrammingError: relation "django_site_domain_v2339b81_uniq" already exists

ProgrammingError: relation "django_session" does not exist error after installing Psycopg2

Django 1.8 test issue: ProgrammingError: relation "auth_user" does not exist

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  7. 7

    Do Idle Snowflake Connections Use Cloud Services Credits?

  8. 8

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  9. 9

    Binding element 'string' implicitly has an 'any' type

  10. 10

    BigQuery - concatenate ignoring NULL

  11. 11

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  12. 12

    In Skype, how to block "User requests your details"?

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Pandas - check if dataframe has negative value in any column

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Generate random UUIDv4 with Elm

  17. 17

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  18. 18

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  19. 19

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  20. 20

    EXCEL: Find sum of values in one column with criteria from other column

  21. 21

    How to use merge windows unallocated space into Ubuntu using GParted?

HotTag

Archive