cp-stack
cp-stack

Reputation: 876

Python Django NameError: name 'model' is not defined

I have a model in one of my apps which is throwing an error when I run "python.py makemigrations signup." I have spent the last two days pouring through documentation (and Google) trying to figure out why this error is happening. Unfortunately I have come up with nothing.

What I am trying to do is include an app in my project. The app sits in the root directory of my python directory (not in a subfolder of of my project). Here is my code:

from django.db import models

class CompanyInfo(models.Model):
        companyID = model.AutoField(primary_key=True)
        companyName = model.CharField(max_length=100)
        companyURL = model.URLField(max_length=100)
        companyEmail = model.EmailField(max_length=254)
        companyFEIN = model.CharField(max_length=50)
        companyUsername= model.CharField(max_length=100)
        companyPassword = model.CharField(max_length=100)

class CompanyContact(models.Model):
        ccID = model.AutoField(primary_key=True)
        ccFirstName = model.CharField(max_length=100)
        ccLastName = model.CharField(max_length=100)
        ccEmail = model.EmailField(max_length=254)
        ccPhone = model.IntegerField(max_length=20)

The exact error that is printed to the console reads:

root@ubuntu1204:/home/humanoid# python manage.py makemigrations humanoid
Traceback (most recent call last):

File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)

File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()

 File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()

File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)

File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)

File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)

File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)

File "/home/humanoid/signup/models.py", line 3, in <module>
    class CompanyInfo(models.Model):

File "/home/humanoid/signup/models.py", line 4, in CompanyInfo
    companyID = model.AutoField(primary_key=True)
NameError: name 'model' is not defined

Upvotes: 1

Views: 6942

Answers (2)

Zach Gates
Zach Gates

Reputation: 4155

It looks like you have dropped the 's' on models. You need to change your use of model to models.

For example:

companyID = model.AutoField(primary_key=True)

Needs to be:

companyID = models.AutoField(primary_key=True)

Upvotes: 4

Eric Scrivner
Eric Scrivner

Reputation: 372

It looks like from the import it should be models (plural) and not model.

Upvotes: 3

Related Questions