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

  • Home
  • SEARCH
  • 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 7189581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:19:56+00:00 2026-05-28T19:19:56+00:00

I have a Django app that uses MySQL as a backend. I’m having difficulties

  • 0

I have a Django app that uses MySQL as a backend. I’m having difficulties where the raw MySQL records show one value, but Django presents something else in the web app.

For example, I have a table for client data. One of the fields in each record is called snailMailInvoice and is a Y/N choice — default is Y (varchar type).

+-------------------+--------------+------+-----+---------+----------------+
| Field             | Type         | Null | Key | Default | Extra          |
+-------------------+--------------+------+-----+---------+----------------+
| snailMailInvoice  | varchar(3)   | NO   |     | Y       |                |

The raw MySQL:

select * from systems_system_contact where lastName="SomeClient";
...a bunch of other fields... | snailMailInvoice |
...a bunch of other fields... | N

Then, in the Django App, the form displays Y (the other choice). It is like the Django App can’t see the MySQL value, so it defaults to Y. If, through the Django App, I select N and save the form, THEN the value sticks to N in Django.

Why would this be happening?

EDIT – to add some code

Forms.py:

class System_Contact_Form(ModelForm):
    class Meta:
        model = System_Contact
        exclude = ('isMainContact', 'systemOwner', 'companyName', 'isRessyContact')

Views.py:

def contact_details(request, scID):
    redirect_to = request.REQUEST.get('next', '/systems/contacts/')
    if request.method == 'POST':
        syscontEdit = System_Contact.objects.get(pk=scID)
        form = System_Contact_Form(request.POST, instance=syscontEdit)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect(redirect_to)
    else:
        syscontView = System_Contact.objects.get(pk=scID)
        form = System_Contact_Form(instance=syscontView)

    c = {
        'form':form,
        'cancel':redirect_to
        }

    return render_to_response('pages/systems/contact_details.html', c, context_instance=RequestContext(request))

Models.py:

class System_Contact(models.Model):
IS_MAIN_CONTACT_CHOICES = (
    ('Y', 'Yes'),
    ('N', 'No'),
)

IS_SYSTEM_OWNER_CHOICES = (
    ('Y', 'Yes'),
    ('N', 'No'),
)

IS_RESSY_CONTACT_CHOICES = (
    ('Y', 'Yes'),
    ('N', 'No, this is a commercial contact'),
)

TRADE_CHOICES = (
    ('EL', 'Electrician'),
    ('LA', 'Landscaper'),
    ('PL', 'Plumber'),
    ('TR', 'Trencher'),
)

SNAIL_MAIL_CHOICES = (
    ('Y', 'Yes'),
    ('N', 'No'),
)

SNAIL_MAIL_INVOICE_CHOICES = (
    ('Y', 'Yes'),
    ('N', 'No'),
)


firstInitial = models.CharField(max_length = 10, verbose_name = 'First Initial', blank = True, null = True)
firstName = models.CharField(max_length = 60, verbose_name = 'First Name', blank = True, null = True)
lastName = models.CharField(max_length = 160, verbose_name = 'Last Name', blank = True, null = True)
phonetically = models.CharField(max_length = 100, verbose_name = 'Phonetically', blank = True, null = True)
companyName = models.CharField (max_length = 160, verbose_name = 'Company Name', blank = True, null = True) #Only used for Commercial Owners, no other field needed
homePhone = models.CharField(max_length = 60, verbose_name = 'Home Phone Number', blank = True, null = True)
officePhone = models.CharField(max_length = 60, verbose_name = 'Office Phone Number', blank = True, null = True)
cellPhone = models.CharField(max_length = 60, verbose_name = 'Cell Phone Number', blank = True, null = True)
faxNumber = models.CharField (max_length= 60, blank=True, null=True, verbose_name = 'Fax Number')
isMainContact = models.CharField (max_length = 3, verbose_name = 'Is the Main Contact?', choices = IS_MAIN_CONTACT_CHOICES, default='N')
isRessyContact = models.CharField (max_length = 3, verbose_name = 'Is this a Ressy Contact?', choices = IS_RESSY_CONTACT_CHOICES, default='Y')
isArchived = models.BooleanField(verbose_name = 'Archived?', default = False)
systemOwner = models.CharField (max_length = 3, verbose_name = 'Is a System Owner?', choices = IS_SYSTEM_OWNER_CHOICES, default='N')  #this is just a flag to say they own a system
worksFor = models.CharField (max_length = 70, verbose_name = 'Works For', blank = True, null = True)
tradeType = models.ForeignKey(Contact_Trade, blank=True, null=True, verbose_name='Trade')
emailAddress = models.EmailField(verbose_name = 'Email Address', blank = True, null = True)

billingAddress = models.CharField(max_length = 150, verbose_name = 'Billing Address', blank=True, null=True )
billingCity = models.CharField(max_length = 90, verbose_name = 'Billing City', blank=True, null=True)
billingProvince = models.CharField(max_length = 30, verbose_name = 'Billing Province', blank=True, null=True)
billingPostalCode = models.CharField(max_length = 10, verbose_name = 'Billing Postal Code', blank=True, null=True)
snailMailOnly = models.CharField(max_length = 3, verbose_name = 'Snail Mail Only?', choices = SNAIL_MAIL_CHOICES, default='Y')
snailMailInvoice = models.CharField(max_length = 3, verbose_name = 'Snail Mail Invoice?', choices = SNAIL_MAIL_INVOICE_CHOICES, default='Y')
  • 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-28T19:19:57+00:00Added an answer on May 28, 2026 at 7:19 pm

    OK — I figured it out.

    I realised there was something connected with the fact that in my CSV file, the snailMailInvoice field is the LAST field on each line. Thus, at the end of the line there is a carriage return. I assumed that this was a \n — thus in my MySQL command to import the CSV, I state terminated by '\n'.

    However, the MySQL picked up a ‘\r’ on EVERY line and was adding it to the snailMailInvoice field. Thus, every record has either a Y or a N with a \r attached.

    I amended my MySQL import statement to have: lines terminated with '\r\n' Now everything is working as expected.

    Lesson learned.

    Thanks for the help.

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

Sidebar

Related Questions

I have a django app that uses MySQL as the database backend. It's been
I have a Django app that uses Haystack . Is it possible to show
I have a django project that uses views from an external app. The view
I have a Django app that uses Satchmo in conjunction with Authorize.net. Authorize.net is
I am building a django app that uses SQLAlchemy over MySQL. I am using
I have a ModelForm in my Django app that uses a forms.ModelMultipleChoiceField, which displays
I've recently uploaded an app that uses django appengine patch and currently have a
I have a Django app that gets it's data completely from an external source
I have a Django app that use a django-tagging. I need to port this
This is probably a setting error somewhere. I have a django app that works

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.