1

I am very new to django(version 1.11).I am trying to make a shoppingwebsite and i am confused in creating Order model. In here you can see my first (version 1) models.py

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.contrib.postgres.fields import ArrayField


class Products(models.Model):
    name = models.CharField(max_length = 20 , default='')
    description = models.CharField(max_length = 100 , default='')
    price = models.IntegerField(default=0)
    image = models.ImageField(upload_to='product_image',blank=True)
    vojood = models.BooleanField(default=False)
    unique = models.CharField(max_length = 100 ,default='')
    typ = models.CharField(max_length = 100 ,default='')
    def __str__ (self):
        return self.name
    @classmethod
    def turn_on(prds,pk):
        prds[pk].vojood=true

    @classmethod
    def turn_off(prds,pk):
        prds[pk].vojood=false
class Order(models.Model):
    username = models.CharField(max_length = 300 , default='')
    address = models.CharField(max_length = 300 , default='')
    time = models.IntegerField(default=0)
    price = models.IntegerField(default=0)
    arrived = models.BooleanField(default=False)
    basket = ArrayField(models.CharField(max_length=300,default=''),default=list)
    def __str__ (self):
        return self.username

After python manage.py makemigrations when i tried to migrate the new field (arrayfield) with python manage.py migrate i got a very long error . So the last line was django.db.utils.OperationalError: near "[]": syntax errorSo i deleted the new field(arrayfield) and again i used makemigrations but the error during migrate did not change.And now i cant migrate any field with any type! And here is my Error :

E:\django projects\4\third>python manage.py makemigrations
Migrations for 'shop':
  shop\migrations\0013_auto_20180611_1518.py
    - Alter field basket on order

E:\django projects\4\third>python manage.py migrate
Operations to perform:
  Apply all migrations: accounts, admin, auth, contenttypes, sessions, shop
Running migrations:
  Applying shop.0005_order_prds...Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 63, in
execute
    return self.cursor.execute(sql)
  File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\base.py", line
326, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: near "[]": syntax error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
364, in execute_from_command_line
    utility.execute()
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 283,
 in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 330,
 in execute
    output = self.handle(*args, **options)
  File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py
", line 204, in handle
    fake_initial=fake_initial,
  File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 11
5, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_i
nitial=fake_initial)
  File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 14
5, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_
initial)
  File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 24
4, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Python34\lib\site-packages\django\db\migrations\migration.py", line 1
29, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, projec
t_state)
  File "C:\Python34\lib\site-packages\django\db\migrations\operations\fields.py"
, line 87, in database_forwards
    field,
  File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\schema.py", lin
e 238, in add_field
    self._remake_table(model, create_field=field)
  File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\schema.py", lin
e 198, in _remake_table
    self.create_model(temp_model)
  File "C:\Python34\lib\site-packages\django\db\backends\base\schema.py", line 3
03, in create_model
    self.execute(sql, params or None)
  File "C:\Python34\lib\site-packages\django\db\backends\base\schema.py", line 1
20, in execute
    cursor.execute(sql, params)
  File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 80, in
execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 65, in
execute
    return self.cursor.execute(sql, params)
  File "C:\Python34\lib\site-packages\django\db\utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\Python34\lib\site-packages\django\utils\six.py", line 685, in reraise

    raise value.with_traceback(tb)
  File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 63, in
execute
    return self.cursor.execute(sql)
  File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\base.py", line
326, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: near "[]": syntax error

E:\django projects\4\third>

I also changed the name of array field from prds to basket but you can see in the error the name did not change !!!!! And it runs 0005_order_prds despite the last created migration is 00013_etc !

1 Answer 1

0

I think your problem is that you are using a SQLite database, you need to use a Postgres database - see this similar question.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for answering. I will try.but now i have lots of data in my database if i change database what will happen for them?
you could migrate the contents of your database to the new database - maybe this will help gist.github.com/sirodoht/f598d14e9644e2d3909629a41e3522ad

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.