1

I am not sure what's wrong.
I have tried migrate/makemigrations and that doesnt help, Im working in virtualenv tho.
my models.py

    from django.db import models
import re


# Create your models here.
class Currency(models.Model):
    def __str__(self):
        return self.short
    name = models.CharField(max_length=32, null=True, blank=True)
    country = models.CharField(max_length=50, null=True, blank=True)
    short = models.CharField(max_length=10, null=True, blank=True)


class Source(models.Model):
    def __str__(self):
        return self.name + '({}...)'.format(self.url[:20])
    url = models.URLField()
    name = models.CharField(max_length=250, verbose_name='Source_name')
    timestamp = models.DateTimeField(auto_now_add=True)
    currency = models.ForeignKey(Currency)

    def save(self, *args, **kwargs):
        self.name = ''.join(re.sub('\s+', ' ', self.name).strip())
        super(Source, self).save()


class Product(models.Model):
    def __str__(self):
        return self.name
    name = models.CharField(max_length=250, blank=False)
    prices = models.ManyToManyField(to='Price', blank=True)
    date_creation = models.DateField(auto_now_add=True)
    prod_code = models.CharField(max_length=250, blank=True, null=True)

    def save(self, *args, **kwargs):
        self.name = ''.join(re.sub('\s+', ' ', self.name).strip())
        super(Product, self).save()  

My function that creates objects

def from_csv_to_db(csv_name):  # empty DB
try:
    df = pd.read_csv(csv_name, sep=';')
except FileNotFoundError:
    return ('Please input correct path to csv file or check spelling. Process finished')
for i, row in df.iterrows():
    Currency.objects.get_or_create(short=row['source__currency__short'], id=row['source__currency_id'])
    Product.objects.get_or_create(id=row['product__id'], name=row['product__name'])
    Source.objects.get_or_create(id=row['source__id'], name=row['source__name'], url = row['source__url'],
                                 currency_id=row['source__currency_id'])
    Parser.objects.get_or_create(script=row['script'], boolean=row['boolean'], product_id=row['product__id'],
                                 source_id=row['source__id'])
return 'Done'

However, django does display my models object via queryset in python manage.py shell

from Parser.models import *
Product.objects.all()  
<QuerySet [<Product: test product>, <Product: iphone>, <Product: 
Mac>, <Product: iPad>]>  

however when I run python manage.py dbshell > select * from Parser_product;
I get ERROR: relation "parser_product" does not exist

I use Docker on Debian and this is done remotely.

12
  • 1
    Hello, have you ran python manage.py makemigrations and python manage.py migrate ? EDIT: I see you did, what is the output of those commands? Commented Apr 11, 2018 at 15:18
  • edit: the output is : for makemigrations - No changes detected migrate - No migrations to apply. I even tried specifiying what to migrate (i.e Parser model, that didnt work either) Commented Apr 11, 2018 at 15:20
  • Thats because Django prefix the table name with the appname, i think Commented Apr 11, 2018 at 15:22
  • 1
    Have you added your app to `INSTALLED_APPS' in 'settings.py' ? Looks like django didnt create tables yet Commented Apr 11, 2018 at 15:22
  • Tables are there( the python manage.py dbshell displays them), but I get the ERROR: relation "parser_price" does not exist when I try to access the table. Yeap it is in INSTALLED_APPS :/ Commented Apr 11, 2018 at 15:23

2 Answers 2

1

Gladly I found the solution via python chat in telegram.

The answer would be a raw query

I had to make it SELECT * FROM "Parser_product" < note the quotes.

Thanks to this answer

Sign up to request clarification or add additional context in comments.

Comments

0

Try running the makemigration command along with the app name. This is needed if you have models in the default app. Eg - python manage.py makemigrations parser. Then run the migrate command.

3 Comments

AFAIU, it resembles much more a problem with the raw query not a migration naming one.
I mentioned this as nexla said in one of his comment that he was not able to make migrations.
I was not able because I already had it running, and also did the way you said, the problem was a raw query as @floatingpurr mentioned

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.