Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:07:20+00:00 2026-06-18T00:07:20+00:00

Just starting with Django and have began creating an application for test purposes. However,

  • 0

Just starting with Django and have began creating an application for test purposes. However, when I specify rollercoasters to ManyToMany and add an instance of a Park via the admin UI I get an:
IntreityError, rollercoasters_id may not be NULL

I have just completed a book on this and the code is more or less exact as the books (the code works in the book).

What am I doing wrong?

The application works when I have ForeignKey instead of ManyToMany

 from django.db import models

class Company(models.Model):
    name=models.CharField(max_length=30)
    location=models.CharField(max_length=30)
    website=models.URLField()

    def __unicode__(self):
        return self.name

class Constructor(models.Model):
    name=models.CharField(max_length=30)
    location=models.CharField(max_length=30)
    contactnumber=models.CharField(max_length=30)
    website=models.URLField()   

    def __unicode__(self):
        return self.name

class RollerCoasters(models.Model):
    name=models.CharField(max_length=30)
    dateopenned=models.DateField
    type=models.CharField(max_length=30)
    builtby=models.ForeignKey(Constructor)
    dateopenned=models.DateField()

    def __unicode__(self):
        return self.name

class Parks (models.Model):
    name=models.CharField(max_length=30)
    parent=models.ForeignKey(Company)
    location=models.CharField(max_length=1000)
    rollercoasters=models.ManyToManyField(RollerCoasters)
    dateopenned=models.DateField()

    def __unicode__(self):
        return self.name

Error:

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/admin/Parks/parks/add/

Django Version: 1.4.2
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'Parks',
 'django.contrib.admin',
 'django.contrib.admindocs')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\options.py" in wrapper
  366.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in inner
  196.             return view(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in _wrapper
  25.             return bound_func(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in bound_func
  21.                 return func(self, *args2, **kwargs2)
File "C:\Python27\lib\site-packages\django\db\transaction.py" in inner
  209.                 return func(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\options.py" in add_view
  955.                 self.save_model(request, new_object, form, False)
File "C:\Python27\lib\site-packages\django\contrib\admin\options.py" in save_model
  709.         obj.save()
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save
  463.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save_base
  551.                 result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "C:\Python27\lib\site-packages\django\db\models\manager.py" in _insert
  203.         return insert_query(self.model, objs, fields, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in insert_query
  1593.     return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
  910.             cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\util.py" in execute
  40.             return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py" in execute
  344.             return Database.Cursor.execute(self, query, params)

Exception Type: IntegrityError at /admin/Parks/parks/add/
Exception Value: Parks_parks.rollercoasters_id may not be NULL
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:07:21+00:00Added an answer on June 18, 2026 at 12:07 am

    You can’t just swap between a foreign key and many to many field. If you have a foreign key, Django creates a database column e.g. rollercoaster_id. If you use a many to many, Django creates an intermediary join table.

    To switch from a foreign key to a many to many field, you must do one of the following:

    • drop the tables and then run syncdb so that Django recreates them. You will lose any data.
    • manually update the database schema yourself, using the output of the manage.py sql command as a guide
    • use the schema migration tool South.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a django application I am working on, I have just added the ability
I'm just starting with the django creating your own app tutorial (creating a Poll)
Just finished the Django tutorial. Starting my own project. Using the ManyToMany Relationship example
I am starting to add Tastypie to a very small Django application I'm developing,
I'm just starting with django. It is not quite clear to me, how should
everyone. I'm just starting with django, so sorry for a possibly stupid question. Imagine,
I'm just starting to dive into ASP.net MVC3. I come from a Django background.
Just starting with FactoryGirl. I have a Model named Subscription . It has a
Just starting out with subversion, have set up repos for 3 current projects and
I'm just starting with Python and Django, and using tastypie to create a RESTful

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.