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 7169563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:01:13+00:00 2026-05-28T15:01:13+00:00

Have a Django / MySQL set up. There’s a model, Survey, which currently looks

  • 0

Have a Django / MySQL set up. There’s a model, Survey, which currently looks like…

class Survey(models.Model):

    company = models.ForeignKey('Company')

I want to set up the model, so company can be a null value:

    company = models.ForeignKey('Company', blank = True, null = True)

However, I’m not sure what I should do on the MySQL side to ensure all the existing constraints / models. Do I just alter the column through the console to accept null values? It’s a live database, so I don’t want to experiment too much (my development environment uses SqlLite3).

  • 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-05-28T15:01:15+00:00Added an answer on May 28, 2026 at 3:01 pm

    Update your model so that blank=True, null=True. Then run the sqlall command on your production server (so that it gives the output for MySQL)

    ./manage.py sqlall myapp
    

    Find the create table statement This will show the new definition for the survey_id field.

    CREATE TABLE `myapp_survey` (
    ...
    `survey_id` integer
    ...
    

    Then, in your database shell, modify the column to accept null values using the ALTER TABLE command.

    ALTER TABLE myapp_survey MODIFY company integer;
    

    Be careful, and consider whether you want to run MySQL in your development environment as well. Do you really want to be copying and pasting commands from Stack Overflow into your live DB shell without testing them first?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I have MySQL DB: In Django models: class Record(models.Model): schema_id = models.IntegerField() project_id =
I have a Django project in which multiple processes are accessing the backend mysql
I have a Django my_forms.py like this: class CarSearchForm(forms.Form): # lots of fields like
Previously I have set up a Django with MySQL attached for all of my
I have both, django and mysql set to work with UTF-8. My base.html set
I have these models class User(models.Model): user_name = models.CharField() ph_number = models.CharField() class ExamPaper(models.Model):
I have a Django deployment in production that uses MySQL. I would like to
I have a legacy application which is (currently) using Django to effectively display data.
I have never actually worked for a company which is deploying a Django App

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.