Reputation: 17869
the naming convention for ForeignKey
is to name with the lowercase version of the connected model
, the following is taken from the docs:
class Car(models.Model):
manufacturer = models.ForeignKey(Manufacturer)
# ...
class Manufacturer(models.Model):
# ...
pass
but I have the following models:
class Work(models.model):
class = models.ForeignKey(Class)
#...
class Class(models.model):
#...
pass
As we know, this will raise an error because we cannot set a variable to class
because it is built into python.
will not following the naming conventions actually be a problem in the SQL database creation?
for example:
class Work(models.model):
cls = models.ForeignKey(Class)
#...
class Class(models.model):
#...
pass
will having a different ForeignKey name mess up the SQL table and database creation?
Upvotes: 1
Views: 77
Reputation: 6221
You definitely want to stay away from reserved words such as Class, List, String, etc. Whether it will mess up your database or not, I'm not sure (try it and see!) but it's definitely a bad idea. If it's not a sql problem, it will mess up something somewhere eventually.
I see 'klass' a lot, if you feel like the word class is absolutely necessary. 'Course', perhaps?
Upvotes: 4