I have two tables dim_job and dim_stream when i do python manage.py inspectdb > models.py.......... then below shown models.py(class shown) is created in django........ dim_job table has three attributes where job_name and alias combined as primary key......here alias is also a foreign key referencing dim_stream table alias. dim_stream table has two attributes where alias is primary key........... When i try to execute DimJob.objects.all() shows error.? How can data be fetched from dim_job table?django queries?
In error i see that dim_job.id doesn't exist ....I don't understand why it is showing this?Already there is combined primary key(job_name,alias) .
I am using postgres database
class DimJob(models.Model):
job_name = models.CharField(max_length=50)
alias = models.ForeignKey('DimStream', db_column='alias')
job_start_time = models.CharField(max_length=20, blank=True, null=True)
class Meta:
managed = False
db_table = 'dim_job'
unique_together = (('job_name', 'alias'),)
class DimStream(models.Model):
stream_name = models.CharField(max_length=50, blank=True, null=True)
alias = models.CharField(primary_key=True, max_length=50)
class Meta:
managed = False
db_table = 'dim_stream'
def __str__(self):
return self.stream_name
Error:
DimJob.objects.all()
Traceback (most recent call last):
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\core\management\commands\shell.py",
line 69, in handle
self.run_shell(shell=options['interface'])
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\core\management\commands\shell.py",
line 61, in run_shell
raise ImportError
ImportError
During handling of the above exception, another exception
occurred:
Traceback (most recent call last):
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\db\backends\utils.py", line 64, in
execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: column dim_job.id does not exist
LINE 1: SELECT "dim_job"."id", "dim_job"."job_name",
"dim_job"."alia...
^
The above exception was the direct cause of the following
exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\db\models\query.py", line 138, in
__repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\db\models\query.py", line 162, in
__iter__
self._fetch_all()
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\db\models\query.py", line 965, in
_fetch_all
self._result_cache = list(self.iterator())
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\db\models\query.py", line 238, in
iterator
results = compiler.execute_sql()
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\db\models\sql\compiler.py", line
829, in execute_sql
cursor.execute(sql, params)
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\db\backends\utils.py", line 79, in
execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\db\backends\utils.py", line 64, in
execute
return self.cursor.execute(sql, params)
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\db\utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\utils\six.py", line 658, in reraise
raise value.with_traceback(tb)
File "C:\Users\vivekre\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\django\db\backends\utils.py", line 64, in
execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column dim_job.id does not exist
LINE 1: SELECT "dim_job"."id", "dim_job"."job_name",
"dim_job"."alia...