Tuesday, December 22, 2015

I'm missing something with Models and database migrations

Python 3.3 and Django 1.8 running on Openshift with a Postgresql database

I'm trying to set up an Invoices table, a Line_Item table, and a cross reference between them. Here are the relevant models:


class Invoices(models.Model):
 invoice_date
= models.DateField('created date', auto_now=True)

class Line_Items(models.Model):
 descr
= models.CharField(max_length=100)
 cost
= models.DecimalField(max_digits=5, decimal_places=2)

class Invoice_Line_Items_Xref(models.Model):
 created_dt
= models.DateField(auto_now=True)
 invoice_id
= models.IntegerField(default=0)
 line_item_id
= models.IntegerField(default=0)
 invoice_id
= models.ManyToManyField(Invoices)
 line_item_id
= models.ManyToManyField(Line_Items)



I don't think the syntax for the cross reference table above is correct, but it is one of the permutations that I've tried. The layout above resulted in this migration after running makemigrations

operations = [
 migrations
.AddField(
 model_name
='invoice_line_items_xref',
 name
='invoice_id',
 field
=models.ManyToManyField(to='gpga.Invoices'),
 
),
 migrations
.AddField(
 model_name
='invoice_line_items_xref',
 name
='line_item_id',
 field
=models.ManyToManyField(to='gpga.Line_Items'),
 
),
]



However, when I push the code to Openshift, even though the migration runs against the database, the invoice_id and line_item_id columns do not appear on the database table.

I have no idea what I'm doing wrong. Thank you for any help.

--Michael

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9953458c-908d-4376-89f9-eb68e37d527a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment