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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:34:19+00:00 2026-06-16T09:34:19+00:00

I tried to run this example on my computer but when I restart the

  • 0

I tried to run this example on my computer but when I restart the python surprisingly the created polls are saved to the database without a visible save statement.

Here is the code:

>>> from polls.models import Poll, Choice
>>> Poll.objects.all()[0].choice_set.create(choice='Not much', votes=0)
<Choice: Not much>

So I wonder by which statements save instructions are implied ? Because if I create it like this, it won’t survive a restart.

>>> c = Choice(choice='Not much3', votes=0)
>>> c.poll_id = 1

I am creating a choice and I am assigning the foreign key poll_id to the first poll. I know this shouldn’t last because I didn’t save. It is the first one that tricks me, I assume if I create it within the associated set it also automatically saves not only gives it’s proper foreign id.

I am also new to python, and semantics seemed just a little bit loose based on my prior experience on this issue. I’d expect first code to just assign the proper foreign id not also save it to the database.

  • 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-16T09:34:20+00:00Added an answer on June 16, 2026 at 9:34 am

    Using the create() method on a QuerySet will automatically save the object, as specified in the documentation.

    You can think of it as effectively an SQL INSERT statement.

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

Sidebar

Related Questions

I tried to run this example but I got binding problem. Designer highlights the
I tried to compile this example on my computer, and all apps have errors
I've tried to run this code locally, but the map doesn't show up. https://developers.google.com/fusiontables/docs/samples/change_query
I tried to run this code: #define ROW_CNT 8; #define COLUMN_CNT 24; #define FIRST_COLUMN
I am logged into my server as root and tried to run this command:
How do I run this command with subprocess? I tried: proc = subprocess.Popen( '''ECHO
I just tried to run my test app and I got this error: 2012-06-16
This problem was discovered when I tried to run the Android emulator in Eclipse.
im really desperate right now, ive tried everything. Everytime i run my app this
Error I tried this page to run on local, it is running perfectly fine

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.