Answer the question
In order to leave comments, you need to log in
How to fix UndefinedTable error in Django?
How to fix the code so that everything is in order. Yes, there are a lot of errors, most likely, I am a complete zero so far in Django, and I am new to Python.
from django.db import models
from django.urls import reverse
from django.utils.datastructures import DictWrapper
from django.utils.dateparse import (parse_date, parse_datetime, parse_duration, parse_time,)
import datetime
class VMs(models.Model):
ID_VM = models.BigIntegerField(primary_key=True)
UUID_VM = models.CharField(max_length=50)
VM_NAME = models.CharField(max_length=50)
BGDATE = models.DateField(auto_now_add=True)
ENDDATE = models.DateField
def __str__(self):
return '%s, %s, %s, %s' % (self.UUID_VM, self.VM_NAME, self.BGDATE, self.ENDDATE)
class VM_PARMS(models.Model):
VM_PRMS = models.BigIntegerField(primary_key=True )
TITLE = models.CharField(max_length=255)
TYPE = models.CharField(max_length=50)
class VM_STATS(models.Model):
ID_VM_STAT = models.BigIntegerField(primary_key=True)
VM_ID = models.ForeignKey(VMs, on_delete=models.CASCADE)
DATE_UPDATE = models.DateField
VM_PRMS = models.ForeignKey(VM_PARMS,on_delete=models.CASCADE)
VALUE = models.IntegerField
def __str__(self):
return '%s, %s, %s' % (self.DATE_UPDATE, self.VM_PRMS, self.VALUE)
[email protected] ~/VMware_Analyst/VMware_Analyst $ python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, catalog, contenttypes, sessions
Running migrations:
Applying catalog.0002_remove_vm_stats_value...Traceback (most recent call last):
File "/home/overlord/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "catalog_vm_stats" does not exist
Answer the question
In order to leave comments, you need to log in
I found a simple solution myself.
First we go here and create the code for your tables, in my case Postgre (the solution for those who cannot create it themselves), then we export it to ourselves.
After that, directly, through the Postgre console, we create tables.
Then we read here https://djbook.ru/rel1.6/howto/legacy-databases.html
Good luck to everyone!
Where did you get such table names in the database, did you create them yourself? then
either https://docs.djangoproject.com/en/3.0/howto/legacy...
or https://docs.djangoproject.com/en/3.0/ref/models/o...
PS and how to call j https://docs.djangoproject.com/en/dev/internals/co... and then blood from the eyes
PS and you definitely need to know the difference between models.DateField vs models.DateField ()
ZZYY do you have exactly postgres there? and then some MS nvarchar
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question